| home | send comment | send link | add bookmark |

Complex number raised to a complex power

by Stephen R. Schmitt


Introduction

A complex number is defined as:

z = a + j·b

where a and b are real numbers and j2 = -1. For the imaginary number j, we can verify that jj is a real number. To show this, recall Euler's formula:

ej·θ = cos(θ) + j·sin(θ)
where e is the base of natural logarithms. Now let θ = π/2. Since
cos(π/2) = 0 and
sin(π/2) = 1
we get
j = ejπ/2
Then, using some algebra
jj = (eπ/2)j = ej·j·π/2 = e-π/2,
which is equal to 0.20787957635 and is a real number.

A derivation

We can use Euler's formula to raise a real number to a complex power. Any real number r can be written as eln r - so the complex power of a real number is:

rj·z = (eln r)j·z 
    = e(j·z·ln r)
    = cos(z·ln r) + j·sin(z·ln r)
To raise a complex number x = a + j·b to the complex power y = c + j·d we can now do the following:
xy = (a + j·b)c + j·d
Using Euler's formula, let
a + j·b = ρ·ej·θ
where,
ρ = √(a2 + b2)
θ = arctan( b/a )      assure θ is in the correct quadrant
By substitution, we get
xy = (ρ·ej·θ)c·(ρ·ej·θ)j·d
Expanding, we get
   = ρc·ej·c·θ·ρj·d·ej·j·d·θ
   = ρc·e-d·θ·ej·c·θ·ρj·d
   = ρc·e-d·θ·[cos(c·θ) + j·sin(c·θ)]·[cos(d·ln ρ) + j·sin(d·ln ρ)]
   = ρc·e-d·θ·{[cos(c·θ)·cos(d·ln ρ) - sin(c·θ)·sin(d·ln ρ)] +
            j·[cos(c·θ)·sin(d·ln ρ) + sin(c·θ)·cos(d·ln ρ)]}
   = ρc·e-d·θ·[cos(c·θ + d·ln ρ) + j·sin(c·θ + d·ln ρ)]
To summarize, given
x = a + j·b
y = c + j·d
Then
xy = ρc·e-d·θ·[cos(c·θ + d·ln ρ) + j·sin(c·θ + d·ln ρ)]
where,
ρ = √(a2 + b2)
θ = arctan( b/a )      assure θ is in the correct quadrant

Zeno source code

Zeno 1.2 is an interpreter for the Zeno programming language. It is an easy to learn and is suitable for educational purposes.


type complex : record
               re : real
               im : real
               end record

program

    var x, y, z : complex

    x.re := 0
    x.im := 1
    y.re := 0
    y.im := 1
    put "x = ", cstr( x )
    put "y = ", cstr( y )
    cpow( z, x, y )
    put "x^y = ", cstr( z )

    x.re := 1
    x.im := 1
    y.re := 1
    y.im := 1
    put "x = ", cstr( x )
    put "y = ", cstr( y )
    cpow( z, x, y )
    put "x^y = ", cstr( z )

end program

% abs = |x|
function cabs( var x : complex ) : real

    return sqrt( x.re*x.re + x.im*x.im )

end function

% theta = arg(x)
function carg( var x : complex ) : real

    return arctanxy( x.re, x.im )

end function

% pow = x^y
procedure cpow( var pow, x, y : complex )

    var r : real := cabs(x)
    var t : real := carg(x)
    var c : real := y.re
    var d : real := y.im
    
    pow.re := (r^c)*exp(-d*t)*cos(c*t + d*ln(r))
    pow.im := (r^c)*exp(-d*t)*sin(c*t + d*ln(r))

end procedure

% convert complex number to a string
function cstr( var c : complex ) : string

    var s : string

    if c.im >= 0.0 then
        s := frealstr( c.re, 14, 9 ) & " + " & frealstr( +c.im, 12, 9 ) & "j"
    else
        s := frealstr( c.re, 14, 9 ) & " - " & frealstr( -c.im, 12, 9 ) & "j"
    end if

    return s

end function

Sample output

x =    0.000000000 +  1.000000000j
y =    0.000000000 +  1.000000000j
x^y =    0.207879576 +  0.000000000j
x =    1.000000000 +  1.000000000j
y =    1.000000000 +  1.000000000j
x^y =    0.273957254 +  0.583700759j

AbCd Classics - free on-line books


Copyright © 2005, Stephen R. Schmitt