Complex cube root

=Introduction=

Let complex numbers $$W =$$ a $$+$$ b$$\cdot i$$ and $$w =$$ p $$+$$ q$$\cdot i.$$ Let $$W = w^3.$$

When given $$a, b,$$ aim of this page is to calculate $$p, q.$$

In the diagram complex number $$w = p + qi = w_{real} + i\cdot w_{imag} = w_{mod}(\cos w_{\phi} + i\cdot \sin w_{\phi}),$$ where


 * $$w_{real}, w_{imag}$$ are the real and imaginary components of $$w,$$ the rectangular components.


 * $$w_{mod}, w_{\phi}$$ are the modulus and phase of $$w,$$ the polar components.

Similarly, $$W_{real}, W_{imag}, W_{mod}, W_{\phi}$$ are the corresponding components of $$W.$$

$$W = w^3 = ( w_{mod}(\cos w_{\phi} + i\cdot \sin w_{\phi}) )^3$$

$$= w_{mod}^3(\cos (3 w_{\phi}) + i\cdot \sin (3 w_{\phi}))$$

$$= W_{mod}(\cos (W_{\phi}) + i\cdot \sin (W_{\phi}))$$

$$= W$$

There are 2 significant calculations:

$$w_{mod} = \sqrt[3]{W_{mod}}$$ and

$$\cos w_{\phi} = \cos \frac{W_{\phi}}{3}.$$

=Implementation=

Cos φ from cos 3φ
The cosine triple angle formula is: $$\cos (3\theta) = 4 \cos^3\theta - 3 \cos\theta.$$ This formula, of form $$y = 4 x^3 - 3 x,$$ permits $$\cos (3\theta)$$ to be calculated if $$\cos\theta$$ is known.

If $$\cos (3\theta)$$ is known and the value of $$\cos\theta$$ is desired, this identity becomes: $$4 \cos^3\theta - 3 \cos\theta - \cos (3\theta) = 0.$$ $$\cos\theta$$ is the solution of this cubic equation.

In fact this equation has three solutions, the other two being $$\cos (\theta \pm 120^\circ).$$

$$\cos (3(\theta \pm 120^\circ)) = \cos (3\theta \pm 360^\circ) = \cos (3\theta).$$

It is sufficient to calculate only $$\cos\theta$$ from $$\cos 3\theta,$$ accomplished by the following code:

When $$x == 1,$$ slope $$= 12x^2 - 3 = 9.$$ Within area of interest, maximum absolute value of slope $$= 9,$$ a rather small value for slope.

Consequently, with only 9 passes through loop, Newton's method produces a result accurate to 200 places of decimals.

There are 3 conditions, any 1 of which terminates the loop:


 * very close to 0 (normal termination).


 * count expired.


 * endless loop detected with the same value of  repeated.

Calculation of 1 root
For function  see  Cube_root#Implementation

Calculation of 3 roots
See Cube roots of unity.

The cube roots of unity are : $$1, \frac{-1 \pm i\sqrt{3}}{2}.$$

When $$r_0 = \sqrt[3]{W}$$ is known, the other 2 cube roots are:


 * $$r_1 = r_0 \cdot \frac{-1 + i\sqrt{3}}{2}$$


 * $$r_2 = r_0 \cdot \frac{-1 - i\sqrt{3}}{2}$$

=Testing results=

$$(p + q\cdot i)^3 = p^3 - 3pq^2 + (3p^2q - q^3)\cdot i = a + b\cdot i.$$

$$a = p^3 - 3pq^2;\ b = 3p^2q - q^3.$$

=Gallery=

=Method #2 (Graphical)=

Introduction
Let complex number $$w = p + qi.$$

Then $$W = w^3 = (p + qi)^3 = p^3 - 3pq^2 + (3p^2q - q^3)i.$$

Let $$W = a + bi.$$

Then:

$$a = p^3 - 3pq^2$$ and

$$b = 3p^2q - q^3.$$

When $$W$$ is given and $$w$$ is desired, $$w$$ may be calculated from the solutions of 2 simultaneous equations:

$$p^3 - 3pq^2 - a = 0\ \dots\ (1)$$ and

$$3p^2q - q^3 - b = 0\ \dots\ (2).$$

For example, let $$W = (39582 + 3799i).$$

Then equations $$(1)$$ and $$(2)$$ become (for graphical purposes):

$$x^3 - 3xy^2 - 39582 = 0\ \dots\ (3),$$ black curve in diagram, and

$$3x^2y - y^3 - 3799 = 0\ \dots\ (4),$$ red curve in diagram.

Three points of intersection of red and black curves are:

$$(-18, 29),$$

$$(34.11473670974872, 1.0884572681198943),$$ and

$$(-16.11473670974872, -30.088457268119896),$$

interpreted as the three complex cube roots of $$W,$$ namely:

$$w_0 = (-18 + 29i),$$

$$w_1 = (34.11473670974872 + 1.0884572681198943i)$$ and

$$w_2 = (-16.11473670974872 - 30.088457268119896i).$$

Proof:

Preparation
This method depends upon selection of most appropriate quadrant.

In the example above, quadrant $$2$$ is chosen because any non-zero positive value of $$y$$ intersects red curve and any non-zero negative value of $$x$$ intersects black curve.

Figures 1-4 below show all possibilities of $$\pm a$$ and $$\pm b.$$

Four points
Assume that $$W = -39582 - 3799i,$$ in which case both $$a, b$$ are negative and quadrant $$4$$ is chosen.

In quadrant $$4$$ any non-zero positive value of x intersects black curve and any non-zero negative value of y intersects red curve.

Choose any convenient negative, non-zero value of $$y.$$

Let $$y = -18.$$

Using this value of $$y,$$ calculate coordinates of point $$A$$ on red curve.

Using $$x$$ coordinate of point $$A,$$ calculate coordinates of point $$B$$ on black curve.

Using $$y$$ coordinate of point $$B,$$ calculate coordinates of point $$C$$ on red curve.

Using $$x$$ coordinate of point $$C,$$ calculate coordinates of point $$D$$ on black curve.

Points $$A, B, C, D$$ enclose the point of intersection of the 2 curves.

Point of intersection
Calculate equations of lines $$AC, BD.$$

Calculate coordinates of point $$E,$$ intersection of lines $$AC, BD.$$

Point $$E$$ is used as starting point for next iteration.

Area of quadrilateral $$ABCD$$ becomes smaller and smaller until complex cube root, intersection of red and black curves, is identified.

An Example
=Method #3 (Algebraic)=

Introduction
Let complex number $$w = p + qi.$$

Then $$W = w^3 = (p + qi)^3 = p^3 - 3pq^2 + (3p^2q - q^3)i.$$

Let $$W = a + bi.$$

Then:

$$a = p^3 - 3pq^2\ \dots\ (1)$$ and

$$b = 3p^2q - q^3\ \dots\ (2).$$

When $$W$$ is given and $$w$$ is desired, $$w$$ may be calculated from the solutions of 2 simultaneous equations $$(1)$$ and $$(2),$$ where $$a,b$$ are known values, and $$p,q$$ are desired.

Implementation
$$(1)$$ squared: $$a^2 = p^6 - 6p^4q^2\ + 9p^2q^4\dots\ (1a)$$

From $$(2):\ 3p^2q = b + q^3\ \dots\ (2a)$$

$$(1a) * 27q^3:$$

$$27q^3a^2 = 27q^3p^6 - 27q^3(6)p^4q^2\ + 27q^3(9)p^2q^4$$

$$27q^3a^2 = 27(p^2q)^3 - 27(6)p^4q^5\ + 27(9)p^2q^7$$

$$27q^3a^2 = (3p^2q)^3 - 27(6)p^4q^2q^3\ + 27(9)p^2qq^6$$

$$27q^3a^2 = (3p^2q)^3 - 3(6)(9p^4q^2)q^3\ + 27(3)(3p^2q)q^6$$

$$27q^3a^2 = (3p^2q)^3 - 3(6)((3p^2q)^2)q^3\ + 27(3)(3p^2q)q^6$$

Let $$Q = q^3:$$

$$27Qa^2 = (3p^2q)^3 - 3(6)((3p^2q)^2)Q + 27(3)(3p^2q)Q^2\ \dots\ (1b)$$

For $$(3p^2q)$$ in $$(1b)$$ substitute $$ ( b + Q ) : $$

$$27Qa^2 = (b+Q)^3 - 3(6)((b+Q)^2)Q + 27(3)(b+Q)Q^2\ \dots\ (1c)$$

Expand $$(1c),$$ simplify, gather like terms and result is:

$$f(Q) = sQ^3 + tQ^2 + uQ + v\ \dots\ (3)$$ where:

$$ Q =  q ^ 3 $$

$$s = 64$$

$$t = 48b$$

$$u = -(15b^2 + 27a^2)$$

$$v = b^3$$

Calculate one real root of $$(3):\ Q_1$$

$$q_1 = \sqrt [3] {Q_1} $$

From $$(2a):\ p_1 = \sqrt{\frac{b + Q_1}{3q_1}}$$

Check $$p_1$$ against $$(1)$$ to resolve ambiguity of sign of $$p_1.$$

$$p_1 + q_1 i$$ is one cube root of $$W.$$

$$p$$ may be calculated without ambiguity as follows:

$$a = p^3 - 3pq^2\ \dots\ (1)$$ and

$$b = 3p^2q - q^3\ \dots\ (2).$$

From $$(1):\ p^3 - 3q^2p - a = 0\ \dots\ (3)$$

From $$(2):\ 3qp^2 - (Q + b) = 0\ \dots\ (4)$$

Let:

$$A = -3q^2$$

$$B = -a$$

$$C = 3q$$

$$D = -(Q + b)$$

Then $$(3), (4)$$ become:

$$p^3 + Ap + B = 0\ \dots\ (5)$$

$$Cp^2 + D = 0 \ \dots\ (6)$$

$$(5)*D:\ Dp^3 + DAp + DB = 0\ \dots\ (7)$$

$$(6)*B:\ BCp^2 + BD = 0 \ \dots\ (8)$$

$$(7)-(8):\ Dp^3 - BCp^2 + DAp = 0\ \dots\ (9)$$

Simplify $$(9):\ Dp^2 - BCp + DA = 0\ \dots\ (10)$$

Repeat $$(6):\ Cp^2 + D = 0 \ \dots\ (6)$$

$$(10)*C:\ CDp^2 - BCCp + DAC = 0\ \dots\ (11)$$

$$(6)*D:\ CDp^2 + DD = 0 \ \dots\ (12)$$

$$(11)-(12):\ - BCCp + DAC - DD = 0\ \dots\ (13)$$

From $$(13):\ p = \frac{DAC - D^2}{BC^2} = \frac {D(AC - D)} {BC^2}$$

An Example
Calculate cube roots of complex number $$W = 39582 + 3799i.$$



Calculate roots of cubic function: $$y = f (x) $$$$ = 64 x^3 $$$$ + 182352 x^2 $$$$ - 42518323563 x $$$$ + 54828691399 .$$

Three roots are: $$Q_1, Q_2, Q_3 = -27239.53953801976, 1.2895380197588122, 24389$$

Three cube roots of $$W = 39582 + 3799i$$ are:

$$w_1 = (-16.114736709748723 - 30.08845726811989i )$$

$$w_2 = ( 34.11473670974874 +  1.0884572681198943i)$$

$$w_3 = (-18.0              + 29.0i               )$$