<- previous    index    next ->

Lecture 12, complex functions

Some complex functions may be computed accurately from the basic
definition. But, preserving relative accuracy over the complete
domain of a few complex functions requires special techniques.

Note that the domain and range of complex functions may not be
obvious to the average user.

First, look at the mappings from domain z1 to range z2 for some
complex functions:
With Java applets enabled
If this does not work, 
Complex Function Screen Shots

Various identities for elementary functions in the complex plane,
including implementing the complex function using only real functions.

Let   z = x + i y 
then  arg z = arctan y/x       real function using signs of x and y
      modulus z = sqrt(x*x+y*y) = |z|  length of complex vector
      conjugate(z) = x - iy 
      re z = x
      im z = y

SQRT
                      i (arg z)/2
  sqrt z = sqrt(|z|) e

  thus yielding half the angle with magnitude sqrt(|z|)

                modulus z + re z             modulus z - re z
  sqrt z = sqrt ----------------  +/- i sqrt ----------------
                       2                            2
           where the sign of the imaginary part of the result is 
           the sign of the imaginary part of z

                      2    3
                 z   z    z
  sqrt 1+z = 1 + - - -- + -- - ...
                 2   8    16

  sqrt( 0 + i0) = 0 + i0
  sqrt(-0 + i0) = 0 + i0
  sqrt( 0 - i0) = 0 - i0
  sqrt(-0 - i0) = 0 - i0
  sqrt(z)**2 = z
  sqrt(z*z) = z    re z > 0
  sqrt(1/z) = 1/sqrt(z)   not for -0 or negative real axis
  conjugate(sqrt(z)) = sqrt(conjugate(z))  not for -0 or negative real axis
Branch cut:
  The branch cut lies along the negative real axis.
Domain:
  Mathematically unbounded
Range:
  Right half plane including the imaginary axis. The algebraic sign
  of the real part is positive.
  The sign of the imaginary part of the result is the same as the
      sign of im z.


LOG
  log z = ln( modulus z) + i argument z

                 2    3
                z    z
  log 1+z = z - -- + -- - ...       for |z| < 1
                2    3

  log(exp(z)) = z      im z in [-Pi,Pi]
  log(1/z) = -log(z)   not on negative real axis
  conjugate(log(z)) = log(conjugate(z))  not on negative real axis
Branch cut:
  The branch cut lies along the negative real axis.
Domain:
  Modulus z /= 0.0
Range:
  Real part mathematically unbounded, imaginary part in range - Pi to Pi
  The sign of the imaginary part of the result is the same as the
      sign of im z.


EXP
   z    re z                 re z
  e  = e     cos (im z) + i e     sin (im z)

   i x 
  e    = cos(x) + i sin(x)

                2    3
   z           z    z
  e  = 1 + z + -- + -- + ...
               2!   3!

   z    z+i 2Pi
  e  = e                   periodic with period  i 2Pi

  exp(-z) = 1/exp(z)       not on negative real axis
  exp(log(z)) = z          |z| non zero
  conjugate(exp(z)) = exp(conjugate(z))
Branch cut:
  None
Domain:
  re z < ln 'LARGE
Range:
  Mathematically unbounded
  For modulus z = 0.0, the result is 1.0 + z


"**"
   w    (w * ln z)
  z  = e
                            2           3
   w                (w ln z)    (w ln z)
  z  = 1 + w ln z + --------- + --------- + ...  for |z| non zero
                       2!          3!
       w
  log(z ) = w * log(z)


SIN 
  sin z = sin(re z) cosh(im z) + i cos(re z) sinh(im z)

            iz    -iz
           e   - e
  sin z = -----------
              2i

               3    5
              z    z
  sin z = z - -- + -- - ...
              3!   5!

  sin z = cos(z - Pi/2)            periodic with period Pi
  sin(z) = sin(z+2Pi)
  sin z = -i sinh iz 
  sin(arcsin(z)) = z
  sin(z) = -sin(-z)
  conjugate(sin(z)) = sin(conjugate(z))
Domain:
  |im z| < ln 'LARGE


COS
  cos z = cos(re z) cosh(im z) - i sin(re z) sinh(im z)

            iz    -iz
           e   + e
  cos z = -----------
              2

               2    4
              z    z
  cos z = 1 - -- + -- - ...
              2!   4!


  cos z = sin(z + Pi/2)            periodic with period Pi
  cos(z) = cos(z+2Pi)
  cos(z) = cos(-z)
  cos z = cosh iz
  cos(arccos(z)) = z
  conjugate(cos(z)) = cos(conjugate(z))
Domain:
  |im z| < ln 'LARGE


TAN
  tan z = sin z / cos z

              iz    -iz
             e   - e
  tan z = -i ----------          limit = -i when im z > ln 'LARGE
              iz    -iz          limit =  i when im z < - ln 'LARGE
             e   + e

               3     5      7
              z    2z    17z
  tan z = z + -- + --- + ---- + ...              for |z| < 1
              3    15    315


            sin x  cos x          sinh y  cosh y
  tan z = ----------------   +i  ----------------
             2         2            2         2
          cos  x + sinh  y       cos  x + sinh  y


  tan z = cot(Pi/2 - z)            periodic with period Pi
  tan z = tan(z+2Pi)
  tan z = 1/cot z
  tan(z) = -tan(-z)
  tan z = -i tanh iz
  tan(arctan(z))=z
  conjugate(tan(z)) = tan(conjugate(z))
Branch cut:
  None
Domain:
  Mathematically unbounded
Range:
  Mathematically unbounded
  For modulus z = 0.0, the result is z


COT
  cot z = cos z / sin z

             iz    -iz
            e   + e
  cot z = i ----------          limit = i when im z > ln 'LARGE
             iz    -iz          limit = -i when im z < -ln 'LARGE
            e   - e


            sin x  cos x          sinh y  cosh y
  cot z = ----------------   -i  ----------------
             2         2            2         2
          sin  x + sinh  y       sin  x + sinh  y


                   3     5
          1   z   z    2z
  cot z = - - - - -- - --- - ...
          z   3   45   945

  cot z = tan(Pi/2 - z)            periodic with period Pi
  cot(z) = cot(z+2Pi)
  cot(z) = -cot(-z)
  cot z = 1/tan z
  conjugate(cot(z)) = cot(conjugate(z))
Branch cut:
  None
Domain:
  Mathematically unbounded
Range:
  Mathematically unbounded
  For modulus z = 0.0, the result is z




ARCSIN
                                  2
  arcsin z = - i ln(i z + sqrt(1-z ))

                                  
  arcsin z = - i ln(i z + sqrt(1-z)*sqrt(1+z))

                  3     5     7
                 z    3z    5z
  arcsin z = z + -- + --- + ---- + ...        for |z| < 1
                 6    40    112


                             1      3      15
  arcsin z = -i( ln(2iz) - --- - ---- - ----- - ... )  for |z| > 1
                             2      4       6
                           4z    32z    288z


                              2
  arcsin z = arctan(z/sqrt(1-z ))  fix re of result

  arcsin z = 
                     2              2 1/2         2              2 1/2
        arcsin(1/2 (x  + 2 x + 1 + y )    - 1/2 (x  - 2 x + 1 + y )   )

        + i
                           2              2 1/2         2              2 1/2
   csgn(-i x + y) ln(1/2 (x  + 2 x + 1 + y )    + 1/2 (x  - 2 x + 1 + y )

                 2              2 1/2         2              2 1/2 2     1/2
       + ((1/2 (x  + 2 x + 1 + y )    + 1/2 (x  - 2 x + 1 + y )   )  - 1)   )

            note: The csgn function is used to determine in which half-plane
                  (`left' or   `right') the complex-valued expression
                  or number x lies.  It is defined by

                             /  1    if Re(x) > 0 or Re(x) = 0 and Im(x) > 0
                  csgn(x) = <  -1    if Re(x) < 0 or Re(x) = 0 and Im(x) < 0
                             \  0    if x = 0


  arcsin z = pi/2 - arccos z

  arcsin z = -i arcsinh iz

  arcsin(sin(z)) = z
Branch cut:
  The real axis not in  [ -1.0, 1.0 ]
Domain:
  Mathematically unbounded
Range:
  Imaginary part mathematically unbounded, real part in [ -Pi/2, Pi/2 ]
  For modulus z = 0.0, the result is z


ARCCOS
                           1+z         1-z
  arccos z = -i 2 ln( sqrt --- +i sqrt --- )
                            2           2
                                 2
  arccos z = -i ln(z + i sqrt(1-z ) ) 

                       3     5
             Pi       z    3z
  arccos z = -- - z - -- - -- - ...             for |z| < 1
             2        6    40

  arccos z = -i( ln(2z)                         for |z| > 1/sqrt(epsilon)

  arccos z =

                     2              2 1/2         2              2 1/2
        arccos(1/2 (x  + 2 x + 1 + y )    - 1/2 (x  - 2 x + 1 + y )   )

        + i
                         2              2 1/2         2              2 1/2
  csgn(I x - y) ln(1/2 (x  + 2 x + 1 + y )    + 1/2 (x  - 2 x + 1 + y )

                 2              2 1/2         2              2 1/2 2     1/2
       + ((1/2 (x  + 2 x + 1 + y )    + 1/2 (x  - 2 x + 1 + y )   )  - 1)   )

                            2
  arccos z = arctan(sqrt(1-z )/z)  fix re of result

  arccos z = pi/2 - arcsin z

  arccos(cos(z)) = z
Branch cut:
  The real axis not in  [ -1.0, 1.0 ]
Domain:
  Mathematically unbounded
Range:
  Imaginary part mathematically unbounded, real part in  [ 0.0, Pi ]


ARCTAN
  arctan z = -i ( ln(1 + i z) - ln(1 - i z) )/2 

             i    i+z
  arctan z = - ln ---    must be fixed on slit for  iz < -1
             2    i-z

                  3    5    7
                 z    z    z
  arctan z = z - -- + -- - -- + ...            for |z| < 1
                 3    5    7

  arctan z = Pi/2 - arccot z

  arctan z = arccot(1/z)

  arctan z = -i arctanh iz

  arctan(tan(z)) = z

  arctan z = 1/2 arctan(x, 1 - y) - 1/2 arctan(- x, y + 1)

                                     2          2
                                    x  + (y + 1)
                     +i      1/4 ln(-------------)
                                     2          2
                                    x  + (y - 1)



ARCCOT
             i    z-i
  arccot z = - ln --- 
             2    z+i
                       3    5
             Pi       z    z
  arccot z = -- - z + -- - -- + ...             for |z| < 1
             2        3    5

  arccot z = Pi/2 - arctan z

  arccot z = arctan(1/z)

  arccot(cot(z)) = z


  arccot z = 1/2 Pi - 1/2 arctan(x, 1 - y) + 1/2 arctan(- x, y + 1)

                                      2          2
                                     x  + (y + 1)
                           -i 1/4 ln(-------------)
                                      2          2
                                     x  + (y - 1)



Range:
  Imaginary part mathematically unbounded, real part in  [0.0 , Pi]


SINH
  sinh z = sinh(re z) cos(im z) + i cosh(re z) sin(im z) 

            z    -z
           e  - e
  sinh z = --------
             2

                3    5
               z    z
  sinh z = z + -- + -- + ...
               3!   5!

  sinh z = -i cosh(z +i Pi/2)           periodic with period i Pi

  sinh z = -i sin iz


COSH
  cosh z = cosh(re z) cos(im z) + i sinh(re z) sin(im z)

            z    -z
           e  + e
  cosh z = --------
             2

                2    4
               z    z
  cosh z = 1 + -- + -- + ...
               2!   4!

  cosh z = -i sinh(z +i Pi/2)         periodic with period  i Pi

  cosh z = cos iz


TANH
  tanh z = sinh z / cosh z

            z    -z
           e  - e
  tanh z = --------
            z    -z
           e  + e

                3     5     7
               z    2z   17z
  tanh z = z - -- + -- - ---- + ...             for |z| < 1
               3    15   315

  tanh z = -i coth(z +i Pi/2)            periodic with period  i Pi

  tanh z = 1/coth z

  tanh z = -i tan iz

            sinh x  cosh x          sin y  cos y
  tanh z = ----------------   +i  ----------------
               2        2             2        2
           sinh  x + cos  y       sinh  x + cos  y


COTH
  coth z = cosh z / sinh z

            z    -z
           e  + e
  coth z = --------
            z    -z
           e  - e
                    3     5
           1   z   z    2z
  coth z = - + - - -- + --- - ...            for |z| < 1
           z   3   45   945

  coth z = -i tanh(z +i Pi/2)

  coth z = 1/tanh z

            sinh x  cosh x          sin y  cos y
  coth z = ----------------   -i  ----------------
               2        2             2        2
           sinh  x + sin  y       sinh  x + sin  y



ARCSINH
                               2
  arcsinh z = ln(z + sqrt(1 + z ) )

                   3     5     7
                  z    3z    5z
  arcsinh z = z - -- + --- - --- + ...           for |z| < 1
                  6    40    112

                        1     3      15
  arcsinh z = ln(2z) + --- - ---- + ----- - ...   for |z| > 1
                         2      4       6
                       4z    32z    288z

  arcsinh z = -i arcsin iz

  arcsinh(sinh(z)) = z

  arcsinh z =

                         2    2           1/2         2    2           1/2
  csgn(x + I y) ln(1/2 (x  + y  + 2 y + 1)    + 1/2 (x  + y  - 2 y + 1)

                 2    2           1/2         2    2           1/2 2     1/2
       + ((1/2 (x  + y  + 2 y + 1)    + 1/2 (x  + y  - 2 y + 1)   )  - 1)   )

       + i
                     2    2           1/2         2    2           1/2
        arcsin(1/2 (x  + y  + 2 y + 1)    - 1/2 (x  + y  - 2 y + 1)   )


ARCCOSH
                         z+i        z-i
  arccosh z = 2 ln( sqrt --- + sqrt --- )
                          2          2

  arccosh z = ln(z + sqrt(z-1) sqrt(z+1) )    not sqrt(z**2-1)

                        1     3      15
  arccosh z = ln(2z) - --- - ---- - ----- - ...    for |z| > 1
                         2      4       6
                       4z    32z    288z

  arccosh(cosh(z)) = z

  arccosh z =
                                                2              2 1/2
     - csgn(I - I x + y) csgn(I x - y) ln(1/2 (x  + 2 x + 1 + y )

               2              2 1/2
       + 1/2 (x  - 2 x + 1 + y )

                 2              2 1/2         2              2 1/2 2     1/2
       + ((1/2 (x  + 2 x + 1 + y )    + 1/2 (x  - 2 x + 1 + y )   )  - 1)   )

     + i
      csgn(I - I x + y)

                       2              2 1/2         2              2 1/2
          arccos(1/2 (x  + 2 x + 1 + y )    - 1/2 (x  - 2 x + 1 + y )   )


ARCTANH
  arctanh z = ( ln(1+z) - ln(1-z) )/2

              1    1+z
  arctanh z = - ln ---       must fix up on slit for  z > 1
              2    1-z

                   3    5    7
                  z    z    z
  arctanh z = z + -- + -- + -- + ...              for |z| < 1
                  3    5    7

  arctanh z = -i arctan iz

  arctanh(tanh(z)) = z

  arctanh z = arccoth(z) + i Pi/2


                                           2    2
                                    (x + 1)  + y
  arctanh z =                1/4 ln(-------------)
                                           2    2
                                    (x - 1)  + y

             +i  1/2 arctan(y, x + 1) - 1/2 arctan(- y, 1 - x)



ARCCOTH
              1    z+1
  arccoth z = - ln ---      must fix up on slit
              2    z-1
                          3    5
              i Pi       z    z
  arccoth z = ---- + z + -- + -- + ...               for |z| < 1
              2          3    5

  arccoth z = arctanh(z) +i Pi/2

  arccoth z = arctanh(1/z)

  arccoth(coth(z)) = z


                                           2    2
                                    (x + 1)  + y
  arccoth z =                1/4 ln(-------------)
                                           2    2
                                    (x - 1)  + y


         +i  1/2 Pi + 1/2 arctan(y, x + 1) - 1/2 arctan(- y, 1 - x)
 


Range:
  Real part mathematically unbounded, imaginary part in [0.0 , i Pi]


There are many complex functions provided by Ada
generic_complex_elementary_functions.ads

Fortran 90 has a few complex functions
complex_func.f90  source code
complex_func_f90.out  output

Python has many complex functions
test_complex.py3  source code
test_complex_py3.out  output

Haskell has many complex functions
test_complex.hs  source code
test_complex_hs.out  output
Complex.hs  Library module

I programmed some complex functions and utility routines in java.
Complex.java  source code
TestComplex.java  source code test
TestComplex_java.out  output
Csimeq.java  source code
test_Csimeq.java  source code test
test_Csimeq_java.out test output
Cinvert.java  source code
test_Cinvert.java  source code test
test_Cinvert_java.out test output
Cnuderiv.java  source code
test2_Cnuderiv.java  source code test
test2_Cnuderiv_java.out test output

I programmed some complex functions and utility routines in ballerina.
complex_math.bal  source code
complex_math_bal.out  test output

Solving PDE with Complex functions, Complex solutions and Complex boundaries:
First the real, double, version second order, two dimensions
pdenu22_eq.java real source code test
pdenu22_eq_java.out test output
Then, converted to complex, Complex, version (using utilities above)
pdeCnu22_eq.java Complex source code test
pdeCnu22_eq_java.out test output

First the real, double, version fourth order, four dimensions
pde44h_eq.java real source code test
pde44h_eq_java.out test output
Then, converted to complex, Complex, version (using utilities above)
pdeC44h_eq.java Complex source code test
pdeC44h_eq_java.out test output

A much easier conversion to complex in Fortran
simeqC.f90 complex source code
inverseC.f90 complex source code
nuderivC.f90 complex source code
nuderivC_test.f90 complex source code
nuderivC_test_f90.out test output
pdeC44h_eq.f90 Complex source code test
pdeC44h_eq_f90.out test output

Similar maximum errors in real and complex code



MatLab overloads all functions that take floating point 
to also work with complex numbers.
Python need to use cmath.
 
    <- previous    index    next ->

Other links

Go to top