0
$\begingroup$

I'm trying to do complex exponentiation on Javascript but I find hard to convert any of the equations I've read to the programming language.

I'm trying to know how to do $$(a+bi)^{c+di} = magic$$

I've read several posts that I find hard to understand and I'm not sure if I'm understanding the equations right.

I've found 2 approaches so far:

1. MathWorld: Complex Exponentiation

This is the link the to the site MathWorld: Complex Exponentiation

There is a equation there like this:

$$(a+bi)^{c+di} = (a^2+b^2)^{\frac{(c+di)}2} e^{i(c+id)\arg(a+ib)}$$

$$(a+bi)^{c+di} = (a^2+b^2)^{\frac{c}2} e^{-d\arg(a+ib)}*{(cos[c\arg(a+ib)+\frac{1}{2} d \ln(a^2+b^2)]+ i\sin[c\arg(a+ib)+\frac{1}{2} d \ln(a^2+b^2)])}$$

Taking account that: $arg(a+ib)=tan^{-1}(\frac{b}{a})$

This equation is in two lines also on the website and I get a little confused. Can I assume that the result of the avobe equation is:

Real Part

$$(a^2+b^2)^{\frac{c}2} e^{-d\arg(a+ib)}*(cos[c\arg(a+ib)+\frac{1}{2} d \ln(a^2+b^2)] =$$ $$=(a^2+b^2)^{\frac{c}2} e^{-d\tan^{-1}(\frac{b}{a})}*(cos[c\tan^{-1}(\frac{b}{a})+\frac{1}{2} d \ln(a^2+b^2)]$$

Imaginary Part

$$(a^2+b^2)^{\frac{c}2} e^{-d\arg(a+ib)}*(i\sin[c\arg(a+ib)+\frac{1}{2} d \ln(a^2+b^2)]=$$ $$=(a^2+b^2)^{\frac{c}2} e^{-d\tan^{-1}(\frac{b}{a})}*(i\sin[c\tan^{-1}(\frac{b}{a})+\frac{1}{2} d \ln(a^2+b^2)]$$

So, here is the first 2 question:

  • 1.1 Are those 2 assumptions right about the result of the exponentiation ?

  • 1.2 If the assumptions are wrong, which is the best way to solve the equation ?

2.Polar Form of a Complex Number

I've read on different posts and sites that another approach is to convert the number to the polar form of the complex number:

$$a+bi=r\,(cos \,θ+i sin θ)$$ $$r=\sqrt{a^2+b^2}$$ $$θ=arctan(\frac{b}{a})$$

  • 2.2 How could I use the polar form to calculate the result of a complex exponentiation?

$$(a+bi)^{c+di} = r\,(cos \,θ+i sin θ)^{q\,(cos \,∝\,+\,i\,sin ∝)}$$ $$r=\sqrt{a^2+b^2}$$ $$θ=arctan(\frac{b}{a})$$ $$q=\sqrt{c^2+d^2}$$ $$∝=arctan(\frac{d}{c})$$

$\endgroup$
1
$\begingroup$

Apply De Moivre's Theorem and this becomes fairly manageable. $$[r(\cos\theta+i\sin\theta)]^{q\cos\alpha+iq\sin\alpha} =\\ =r^{q\cos\alpha+iq\sin\alpha}(q\cos\theta \cos\alpha-q\sin\theta \sin\alpha +iq\cos\theta \sin\alpha+iq\sin\theta \cos\alpha) = \dots $$ Then the cos and sine addition rules $$\dots = qr^{q\cos\alpha+iq\sin\alpha}(\cos(\theta + \alpha)+i\sin(\theta + \alpha)) = \dots$$ Ignore the second half for now, I will resolve the first half and then multiply the second half back on at the end. $$qr^{q\cos\alpha} r^{iq\sin\alpha} =\\ =qr^{q\cos\alpha} e^{iq\ln(r)\sin\alpha} =\\ =qr^{q\cos\alpha}(\cos⁡(q\ln⁡(r)\sin⁡\alpha)+i\sin⁡(q\ln⁡(r)\sin⁡\alpha)) \,$$ because $r=e^{\ln r}$.

Putting everything back together we get: $$\dots = qr^{q\cos\alpha}[\cos⁡(q\ln⁡(r)\sin⁡\alpha)+i\sin⁡(q\ln⁡(r)\sin⁡\alpha][\cos(\theta + \alpha)+i\sin(\theta + \alpha)] \ ,$$

with every power now comprised of only real numbers. Hope this helps :)

$\endgroup$
  • $\begingroup$ It is better to add a slash in front of the usual mathematical functions in order to make them display more nicely: \cos, \sin, \ln etc. $\endgroup$ – Alex M. Apr 23 '18 at 14:53
  • $\begingroup$ Thanks Alex, still a newbie with all the ins and outs. Does the answer seem good otherwise? $\endgroup$ – Rhys Hughes Apr 23 '18 at 18:14
  • $\begingroup$ Thanks for the answer ! I'll try it to see if the performance is better of what I have right now $\endgroup$ – AlvaroAV Apr 25 '18 at 8:47
  • $\begingroup$ No worries. Hope it's successful $\endgroup$ – Rhys Hughes Apr 27 '18 at 20:10
1
$\begingroup$

It seems you have understood it correctly, but you may also have done it unnecessarily complicated. Because, using only algebra, you can construct a meaningful, if not intuitive, at least more inutitive way of representing complex exponentiation: Let $z = a+bi$ and $w = c+di$. Note: $z = |z|*e^{Arg(z)*i}$ $$z^w = (a+bi)^{c+di}$$$$ = (a+bi)^c*(a+bi)^{di}$$$$ = |z|^c*e^{iArg(z)c}*|z|^{di}*(e^{Arg(z)*i})^{di}$$$$= |z|^c*e^{-Arg(z)d}*e^{ln(|z|)di}*e^{iArg(z)c}$$$$ = \frac{|z|^c}{e^{Arg(z)d}}e^{(Arg(z)c+ln(|z|)d)i}$$ $|z| = \sqrt{Re(z)^2+Im(z)^2}$ ➝ The length of z
$Arg(z) = atan2(Im(z), Re(z))$ ➝ The angle of z
$e^{i\theta} = cos(\theta)+isin(\theta)$ ➝ Euler's formula

Using this formula, you only need to know how to do exponentiation with real numbers, finding the angle of a complex number, finding ln(x), finding |x|, euler's formula, multiplication, division, addition and sometimes subtraction.

Some interesting observations I've made:
- When taking any complex or real number to the power of $i$, the angle and length of the number seem to swap: $z = a+bi, w = 0+1i$ $$z^w = \frac{|z|^0}{e^{Arg(z)*1}}e^{(Arg(z)*0+ln(|z|*1)i} = \frac{1}{e^{Arg(z)}}e^{ln(|z|)i}$$ When taking $z^i$, $1$ divided by $e$ to the power of the angle of $z$, is now the length, and the natural logarithm of the length is now the angle.

- Doing complex exponentiation with a real exponent is essentially a mix of stretching and rotating the base.
- Doing complex exponentiation with an imaginary exponent basically just swaps the length and the angle.
- Doing complex exponentiation with a complex exponent is a mix of the two things mentioned above.


Complex roots
Finding complex roots is very similar to taking complex exponentials, since, as we know: $\sqrt[b]{a} = a^{\frac{1}{b}}$ Having used some basic algebra, I've come up with a similar formula for the wth root of z where $z,w ∈ ℂ$: $$\sqrt[w]{z} = z^{\frac{1}{w}}$$ $$= exp\left(\frac{Arg(z)d+ln(|z|)c}{c^2+d^2}+\frac{Arg(z)c-ln(|z|)d}{c^2+d^2}i\right)$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.