Complex numbers

Maple has complex numbers built in, and sometimes they may appear even if you aren't necessarily expecting them. By default, the imaginary unit (the square root of $-1$) is represented by I; however you can change this easily by using:

[> interface( 'imaginaryunit' = 'j' ):

At this point, you cannot assign to 'j', as far as Maple is concerned, any j is automatically interpreted as the imaginary unit. Unlike other programming languages, you must explicitly place an asterisks between any multiplier and the imaginary unit:

[> 3 + 4*j;

$3 + 4j$

All arithmetic operations work the same, but remember to place parentheses around the complex number if you want to have the entire complex number multiply another value:

[> (3 + j)*z^2 + (4 - 2*j)*z + 5 - 3*j;

$(3 + j)z^2 + (4 - 2j)z + 5 - 3j$

To access the real and imaginary components of a complex number, you can use the Re(...) and Im(...) functions:

[> z0 := 3.25 - 7.21*j:
[> Re( z0 );

$3.25$

[> Im( z0 );

$-7.21$

You can access the absolute value and the angle, argument or phase of a complex number using the abs(...) and argument(...) functions:

[> abs( z0 );

$7.908640844$

[> argument( z0 );

$-1.147308212$

If the argument is a rational complex number (where both real and imaginary components are rational numbers), the result is still correctly calculated:

[> abs( -1/2 - 4/3*j );

$\frac{\sqrt{73}}{6}$

[> argument( -1/2 - 4/3*j );

$\mathrm{arctan}\left( \frac{8}{3} \right) - \pi$

Polar representation

As you are aware, there are both rectangular and polar representations of complex numbers. The polar(...) constructor returns a data structure that represents a complex number in polar coordinates. If there is a single argument, it is assumed to be a complex number in the rectangular representation ($\alpha + \beta j$), in which case, a data structure with the absolute value as the first entry and the angle or phase or argument (in radians) is the second entry:

[> z1 := polar( 1.5 + 3.2*j );

$z1 := polar(3.534119409, 1.132459767)$

[> z2 := polar( 4.5, -2.5 );

$z1 := polar(4.5, -2.5)$

[> Re( z1 ); Im( z1 ); abs( z1 ); argument( z1 );

$1.500000000$

$3.200000000$

$3.534119409$

$1.132459767$

[> Re( z2 ); Im( z2 ); abs( z2 ); argument( z2 );

$-3.605146270$

$-2.693124648$

$4.5$

$-2.5$

Transcendental functions

All of the trigonometric, hyperbolic, exponential, and logarithmic functions accept complex numbers:

[> Re( exp( 3*j ) ); # Euler's formula

$\cos(3)$

[> Im( exp( 3*j ) ); # Euler's formula

$\sin(3)$

[> exp( 2.3*j ); cos( 2.3 ) + sin( 2.3 )*j; # Euler's formula

$-0.6662760213 + 0.7457052122 j$

$-0.6662760213 + 0.7457052122 j$

[> exp( 3 + 5*Pi*j );

$-e^3$

[> abs( exp( 3 + 4*j ) );

$e^3$

[> z0 := 0.3 + 0.6*j:
[> exp( z0 ); 1 + z0 + z0^2/2! + z0^3/3! + z0^4/4! + z0^5/5!;

$1.114086549 + 0.7621876158j$
$1.113967750 + 0.7621305000j$

[> sin( z0 ); z0 - z0^3/3! + z0^5/5! - z0^7/7! + z0^9/9! - z0^11/11!;

$0.3503289263 + 0.6082183980j$
$0.3503289263 + 0.6082183980j$

[> cosh( z0 ); 1 + z0^2/2! + z0^4/4! + z0^6/6! + z0^8/8! + z0^10/10!;

$0.8627551053 + 0.1719450917j$
$0.8627551053 + 0.1719450917j$

Polynomials with complex coefficients

These as one may expect:

[> p := (3 + j)*z^2 + (4 - 2*j)*z + 5 - 3*j:
[> eval( p, z = 1.3 - 2.4*j );

$6.23 - 0.39j$