Say I have a complex number, $a+bi$, and I want to raise it to a whole number power $n$. I know I can calculate it as: $$(a+bi)^n= \sum_0^n{n\choose k}a^{n-k}(bi)^{k}$$ However, I want to be able to calculate the real and imaginary parts separately, for reasons dealing with computer programming that are irrelevant to the question. I attempted this with: $$\Re\{(a+bi)^n\} = a^n-\sum_1^{\lfloor{\frac{n}{2}}\rfloor}{n\choose 2k}a^{n-2k}b^{2k}$$ and $$\Im\{(a+bi)^n\} = i\sum_0^{\lceil{\frac{n}{2}}\rceil}{n\choose 2k+1}a^{n-(2k+1)}b^{2k+1}(-1)^k$$ But I am 100% convinced I have made a mistake and lost the plot on what I'm trying to do.
Am I correct in my thinking? And if not, how could I fix these equations?
Take a look at this thread: