Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I saw this question, and found a formula: $$=\cos \left( d\log |a+bi|+c\arctan \frac{d}{c}\right)+i\sin \left( d\log |a+bi|+c\arctan \frac{d}{c}\right).$$ Which I later translated to Microsoft Math format:
And - that formula gives wrong results.
While the result is -0.507 - 0.861i (for that formula, setting a=1,b=2,c=3,d=4)
Doing (a + bi)^(c + di) gives me 0.129+0.033i
Can anyone explain what I am doing wrong ? (I am trying to write a program which does this.)

share|cite|improve this question
Taking the power of a complex number by a complex number isn't uniquely defined, as is already explained in the question you linked to. – Qiaochu Yuan Aug 8 '11 at 20:33
So how exactly does Microsoft Math calculate it ? – Mark Segal Aug 8 '11 at 20:45
Who knows? I don't even know what that is. – Qiaochu Yuan Aug 8 '11 at 20:47
The veracity of a formula producing a complex number of modulus 1 for every (a+bi)^(c+di), as yours seems to be doing, is highly dubious. Another, similar, remark is that your formula gives 1 for every (a,b,c,d) such that d=0. Hmmm... – Did Aug 8 '11 at 20:56
That wasn't my formula but Americo Tavareses... – Mark Segal Aug 8 '11 at 21:15
up vote 3 down vote accepted

I corrected the answer you cite. Instead of the $\arctan$ function it should be the $\arg$ function. These two functions are not always equal. The $\arg$ function is used in the principal logarithm of $z=x+iy$, which is the complex number

$$w=\text{Log }z=\log |z|+i\arg z$$

so that $e^w=z$, where $\arg z$ (the principal argument of $z$) is the real number in $-\pi\lt \arg z\le \pi$, with $x=|z|\cos (\arg z)$ and $y=|z|\sin (\arg z)$.

The formula now reads as follows:

$$\begin{eqnarray*} \left( a+bi\right) ^{c+di} &=&e^{(c+di)\text{ Log }(a+bi)} \\ &=&e^{(c+di)\left( \ln |a+bi|+i\arg (a+bi)\right) } \\ &=&e^{c\ln \left\vert a+ib\right\vert -d\arg \left( a+ib\right) +i\left( c\arg \left( a+ib\right) +d\ln \left\vert a+ib\right\vert \right) } \\ &=&e^{c\ln \left\vert a+ib\right\vert -d\arg(a+bi)}\times \\ &&\times \left( \cos \left( c\arg \left( a+ib\right) +d\ln \left\vert a+ib\right\vert \right) +i\sin \left( c\arg \left( a+ib\right) +d\ln \left\vert a+ib\right\vert \right) \right). \end{eqnarray*}$$

For $a=1,b=2,c=3,d=4$, we have (numeric computations in SWP)

$$\begin{eqnarray*} \left( 1+2i\right) ^{3+4i} &=&e^{(3+4i)\text{ Log }(1+2i)} \\ &=&e^{(3+4i)\left( \log |1+2i|+i\arg (1+2i)\right) } \\ &=&e^{3\ln \left\vert 1+2i\right\vert -4\arg \left( 1+2i\right) +i\left( 3\arg \left( 1+2i\right) +4\ln \left\vert 1+2i\right\vert \right) } \\ &=&e^{3\ln \left\vert 1+2i\right\vert -4\arg \left( 1+2i\right) }\times \\ &&\times \left( \cos \left( 3\arg \left( 1+2i\right) +4\ln \left\vert 1+2i\right\vert \right) +i\sin \left( 3\arg \left( 1+2i\right) +4\ln \left\vert 1+2i\right\vert \right) \right) \\ &\approx &0.13340\left( \cos \left( 6.5403\right) +i\sin \left( 6.5403\right) \right) \\ &\approx &0.12901+3.3924\times 10^{-2}i, \end{eqnarray*}$$

which agrees with the computation in Wolfram Alpha for $(1+2i)^{3+4i}.$

And for instance, if $a=-1,b=2,c=3,d=4,$ then

$$\begin{eqnarray*} \left( -1+2i\right) ^{3+4i} &=&e^{(3+4i)\text{ Log }(-1+2i)} \\ &=&e^{(3+4i)\left( \log |-1+2i|+i\arg (-1+2i)\right) } \\ &=&e^{3\ln \left\vert -1+2i\right\vert -4\arg \left( -1+2i\right) +i\left( 3\arg \left( -1+2i\right) +4\ln \left\vert -1+2i\right\vert \right) } \\ &=&e^{3\ln \left\vert -1+2i\right\vert -4\arg \left( -1+2i\right) }\times \\ &&\times \left( \cos \left( 3\arg \left( -1+2i\right) +4\ln \left\vert -1+2i\right\vert \right) +i\sin \left( 3\arg \left( -1+2i\right) +4\ln \left\vert -1+2i\right\vert \right) \right) \\ &\approx &3.267\,9\times 10^{-3}\left( \cos \left( 9.3222\right) +i\sin \left( 9.3222\right) \right) \\ &\approx &3.\,250\,7\times 10^{-3}+3.346\times 10^{-4}i. \end{eqnarray*}$$

In Wolfram Alpha we get $(-1+2i)^{3+4i}\approx -0.003250688+0.000334598i$

share|cite|improve this answer
Thank you very much! – Mark Segal Aug 9 '11 at 11:39
@Quantic Programming: You are welcome! Sorry for the errors in my old answer! – Américo Tavares Aug 9 '11 at 11:43

The formula you cite is in Américo Tavares' response to the question. I believe the argument of the $\arctan$ should be $\frac{b}{a}$. When I plug it into Wolfram Alpha with your constants, I get about $0.9671+0.2543i.$ It is the exponential of only the imaginary part, so you need to multiply it by the exponential of the real part: $e^{c\log |a+bi|-d\arctan \frac{b}{a}}\approx 0.1333$ if you expect $(1+2i)^{(3+4i)}$ and it comes out.

share|cite|improve this answer
I corrected the formula in my answer as per your comment. – Américo Tavares Aug 8 '11 at 22:00
+1 ... the argument of the $\arctan$ is $b/a$ indeed. – Américo Tavares Aug 8 '11 at 22:09
Could you please check sign in $−0.2543i$? (I got $0.2543i$) – Américo Tavares Aug 9 '11 at 0:39
@Américo Tavares: I agree. Fixed. Thanks. – Ross Millikan Aug 9 '11 at 0:42
Just an information. In the present case $\arctan 2/1=\arg(1+2i)$ (the principle argument of $(1+2i)$. However, since in general it may be different, e.g. $\arg(-1+2i)=\arctan(-2)+\pi=-\arctan 2+\pi$, I revised my answers and used only $\arg(a+bi)$. – Américo Tavares Aug 9 '11 at 11:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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