Next: Combinatorial Functions, Previous: Functions for Numbers, Up: Mathematical Functions [Contents][Index]

### 10.2 Functions for Complex Numbers

Function: cabs (expr)

  Calculates the absolute value of an expression representing a complex number. Unlike the function `abs`, the `cabs` function always decomposes its argument into a real and an imaginary part. If `x` and `y` represent real variables or expressions, the `cabs` function calculates the absolute value of `x + %i*y` as

      (%i1) cabs (1);
      (%o1)                           1

      (%i2) cabs (1 + %i);
      (%o2)                        sqrt(2)

      (%i3) cabs (exp (%i));
      (%o3)                           1

      (%i4) cabs (exp (%pi * %i));
      (%o4)                           1

      (%i5) cabs (exp (3/2 * %pi * %i));
      (%o5)                           1

      (%i6) cabs (17 * exp (2 * %i));
      (%o6)                          17

  If `cabs` returns a noun form this most commonly is caused by some properties of the variables involved not being known:

      (%i1) cabs (a+%i*b);
                                      2    2
      (%o1)                     sqrt(b  + a )

      (%i2) declare(a,real,b,real);
      (%o2)                         done

      (%i3) cabs (a+%i*b);
                                      2    2
      (%o3)                     sqrt(b  + a )

      (%i4) assume(a>0,b>0);
      (%o4)                    [a > 0, b > 0]

      (%i5) cabs (a+%i*b);
                                      2    2
      (%o5)                     sqrt(b  + a )

  The `cabs` function can use known properties like symmetry properties of complex functions to help it calculate the absolute value of an expression. If such identities exist, they can be advertised to `cabs` using function properties. The symmetries that `cabs` understands are: mirror symmetry, conjugate function and complex characteristic.

  `cabs` is a verb function and is not suitable for symbolic calculations. For such calculations (including integration, differentiation and taking limits of expressions containing absolute values), use `abs`.

  The result of `cabs` can include the absolute value function, `abs`, and the arc tangent, `atan2`.

  When applied to a list or matrix, `cabs` automatically distributes over the terms. Similarly, it distributes over both sides of an equation.

  For further ways to compute with complex numbers, see the functions `rectform`, `realpart`, `imagpart`, `carg`, `conjugate` and `polarform`.

  Examples:

  Examples with `sqrt` and `sin`.

      (%i1) cabs(sqrt(1+%i*x));
                                   2     1/4
      (%o1)                      (x  + 1)
      (%i2) cabs(sin(x+%i*y));
                          2        2         2        2
      (%o2)       sqrt(cos (x) sinh (y) + sin (x) cosh (y))

  The error function, `erf`, has mirror symmetry, which is used here in the calculation of the absolute value with a complex argument:

      (%i3) cabs(erf(x+%i*y));
                                                2
                 (erf(%i y + x) - erf(%i y - x))
      (%o3) sqrt(--------------------------------
                                4
                                                                     2
                                      (erf(%i y + x) + erf(%i y - x))
                                    - --------------------------------)
                                                     4

  Maxima knows complex identities for the Bessel functions, which allow it to compute the absolute value for complex arguments. Here is an example for `bessel_j`.

      (%i4) cabs(bessel_j(1,%i));
      (%o4)                 abs(bessel_j(1, %i))

  Categories:Complex variables ·

Function: carg (z)

  Returns the complex argument of z. The complex argument is an angle `theta` in `(-%pi, %pi]` such that `r exp (theta %i) = z` where `r` is the magnitude of z.

  `carg` is a computational function, not a simplifying function.

  See also `abs` (complex magnitude), `polarform`, `rectform`, `realpart`, and `imagpart`.

  Examples:

      (%i1) carg (1);
      (%o1)                           0

      (%i2) carg (1 + %i);
                                     %pi
      (%o2)                          ---
                                      4

      (%i3) carg (exp (%i));
                                     sin(1)
      (%o3)                     atan(------)
                                     cos(1)

      (%i4) carg (exp (%pi * %i));
      (%o4)                          %pi

      (%i5) carg (exp (3/2 * %pi * %i));
                                      %pi
      (%o5)                         - ---
                                       2

      (%i6) carg (17 * exp (2 * %i));
                                  sin(2)
      (%o6)                  atan(------) + %pi
                                  cos(2)

  If `carg` returns a noun form this most commonly is caused by some properties of the variables involved not being known:

      (%i1) carg (a+%i*b);
      (%o1)                      atan2(b, a)

      (%i2) declare(a,real,b,real);
      (%o2)                         done

      (%i3) carg (a+%i*b);
      (%o3)                      atan2(b, a)

      (%i4) assume(a>0,b>0);
      (%o4)                    [a > 0, b > 0]

      (%i5) carg (a+%i*b);
                                        b
      (%o5)                        atan(-)
                                        a

  Categories:Complex variables ·

Function: conjugate (x)

  Returns the complex conjugate of x.

      (%i1) declare ([aa, bb], real, cc, complex, ii, imaginary);
      (%o1)                         done

      (%i2) conjugate (aa + bb*%i);
      (%o2)                      aa - %i bb

      (%i3) conjugate (cc);
      (%o3)                     conjugate(cc)

      (%i4) conjugate (ii);
      (%o4)                         - ii

      (%i5) conjugate (xx + yy);
      (%o5)                        yy + xx

  Categories:Complex variables ·

Function: imagpart (expr)

  Returns the imaginary part of the expression expr.

  `imagpart` is a computational function, not a simplifying function.

  See also `abs`, `carg`, `polarform`, `rectform`, and `realpart`.

  Example:

      (%i1) imagpart (a+b*%i);
      (%o1)                           b

      (%i2) imagpart (1+sqrt(2)*%i);
      (%o2)                        sqrt(2)

      (%i3) imagpart (1);
      (%o3)                           0

      (%i4) imagpart (sqrt(2)*%i);
      (%o4)                        sqrt(2)

  Categories:Complex variables ·

Function: polarform (expr)

  Returns an expression `r %e^(%i theta)` equivalent to expr, such that `r` and `theta` are purely real.

  Example:

      (%i1) polarform(a+b*%i);
                             2    2    %i atan2(b, a)
      (%o1)            sqrt(b  + a ) %e

      (%i2) polarform(1+%i);
                                        %i %pi
                                        ------
                                          4
      (%o2)                   sqrt(2) %e

      (%i3) polarform(1+2*%i);
                                      %i atan(2)
      (%o3)                 sqrt(5) %e

  Categories:Complex variables ·Exponential and logarithm functions ·

Function: realpart (expr)

  Returns the real part of expr. `realpart` and `imagpart` will work on expressions involving trigonometric and hyperbolic functions, as well as square root, logarithm, and exponentiation.

  Example:

      (%i1) realpart (a+b*%i);
      (%o1)                           a

      (%i2) realpart (1+sqrt(2)*%i);
      (%o2)                           1

      (%i3) realpart (sqrt(2)*%i);
      (%o3)                           0

      (%i4) realpart (1);
      (%o4)                           1

  Categories:Complex variables ·

Function: rectform (expr)

  Returns an expression `a + b %i` equivalent to expr, such that a and b are purely real.

  Example:

      (%i1) rectform(sqrt(2)*%e^(%i*%pi/4));
      (%o1)                        %i + 1

      (%i2) rectform(sqrt(b^2+a^2)*%e^(%i*atan2(b, a)));
      (%o2)                       %i b + a

      (%i3) rectform(sqrt(5)*%e^(%i*atan(2)));
      (%o3)                       2 %i + 1

  Categories:Complex variables ·

Next: Combinatorial Functions, Previous: Functions for Numbers, Up: Mathematical Functions [Contents][Index]