COMPLEX ANALYSIS -- BASIC MAPLE COMMANDS

Dr. John C. Nardo, Associate Professor

Mathematics & Computer Science

Oglethorpe University

Atlanta, GA

jnardo@oglethorpe.edu

Maple capitalizes the imaginary unit i from Complex Analysis.  You will be tempted to use lower-case i; fight this impulse.  

Also remember in Maple there is no "implied multiplication."  So, if you want to multiply, you must use an asterix.

You "name" objects in Maple using colon and the equal sign.

> z1:=2+3*I;

z1 := 2+3*I

> z2:=10-9*I;

z2 := 10-9*I

Maple performs all of our usual arithmetic operations on complex numbers.

> z1+z2;

12-6*I

> z1-z2;

-8+12*I

> z1*z2;

47+12*I

> z1/z2;

-7/181+48/181*I

Notice that Maple will try to return a complex number in standard a + bi form.  If it does not, then you can force this to happen using the evalc command (evaluate complex expression).

> sqrt(1+I);

(1+I)^(1/2)

> evalc(sqrt(1+I));

1/2*(2+2*2^(1/2))^(1/2)+1/2*I*(-2+2*2^(1/2))^(1/2)

Maple can also calculate a complex number's conjugate using the naturally named conjugate command.  Again use the evaluate complex expression evalc command to force standard a + bi form when you get unexpected results.

> z1;

2+3*I

> conjugate(z1);

2-3*I

> z2;

10-9*I

> conjugate(z2);

10+9*I

> sqrt(1+I);

(1+I)^(1/2)

> evalc(sqrt(1+I));

1/2*(2+2*2^(1/2))^(1/2)+1/2*I*(-2+2*2^(1/2))^(1/2)

> conjugate(sqrt(1+I));

(1-I)^(1/2)

> evalc(conjugate(sqrt(1+I)));

1/2*(2+2*2^(1/2))^(1/2)-1/2*I*(-2+2*2^(1/2))^(1/2)

Maple again uses the naturally named commands Re and Im to find the real and imaginary parts, respectively, of a complex number.

> Re(z1);

2

> Im(z1);

3

> Re(z2);

10

> Im(z2);

-9

> Re(sqrt(1+I));

1/2*(2+2*2^(1/2))^(1/2)

> Im(sqrt(1+I));

1/2*(-2+2*2^(1/2))^(1/2)

Maple calculates the modulus (via the abs command) and Argument of a complex number (via the argument command).  

Note that Maple is not being exactly precise with its command names!  We know there is a difference between Arg(z) and arg(z).  The first is the name for a unique angle in the half-open interval (-Pi, Pi].  The second is the name for the infinity family of all possible angles.  Since it is returning the one unique angle, Maple should capitalize its argument command, but unfortunately, it does not.  Be mindful of this subtle programming oversight.  

For special angles, Maple will try to return an exact angle.  For other angles, it will simply return the inverse tangent definition (with a + or - to adjust for reference angles).  You can then use the evalf command to force a floating point/decimal number of radians, if needed.  Notice the percent sign % can be used to refer to the last calculation that Maple performed.  

> abs(z1);

13^(1/2)

> abs(z2);

181^(1/2)

> abs(7+0*I);

7

> abs(0+7*I);

7

> abs(-7+0*I);

7

> abs(0-7*I);

7

> argument(z1);

arctan(3/2)

> evalf(%);

.9827937232

> argument(z2);

-arctan(9/10)

> evalf(%);

-.7328151018

> argument(7+0*I);

0

> argument(0+7*I);

1/2*Pi

> argument(-7+0*I);

Pi

> argument(0-7*I);

-1/2*Pi

> argument(-1-I);

-3/4*Pi

> argument(-sqrt(3)+I);

5/6*Pi

Using Maple to calculate the modulus and argument of a complex number, you can "manually" find the polar form of a complex number.  Maple also has a command to streamline the exhausting task of typing two commands to get an "answer."  You can use the convert command.

> -1-I;abs(-1-I);argument(-1-I);

-1-I

2^(1/2)

-3/4*Pi

> convert(-1-I,polar);

polar(2^(1/2), -3/4*Pi)

Maple can easily calculate values of the exponential function for both real and complex numbers using the exp command.  You may need the evalc and evalf commands to force Maple to give the output you desire.

> exp(2);

exp(2)

> evalf(exp(2));

7.389056099

> exp(1+I);

exp(1+I)

> evalc(exp(1+I));

exp(1)*cos(1)+I*exp(1)*sin(1)

> evalf(%);

1.468693940+2.287355287*I

>

Recall how you make functions in Maple via the following syntax:  

name of function : = variable(s) -> rule; .

> f:=x->arcsin(x^2+1);

f := proc (x) options operator, arrow; arcsin(x^2+1) end proc

> f(0);

1/2*Pi

> g:=(x,y)->exp(x+y);

g := proc (x, y) options operator, arrow; exp(x+y) end proc

> g(1/4,3/4);

exp(1)

We can use this functional structure in Maple to "automate" the complicated root finding process from class.  

Suppose we wish to find the nth root of a complex number.  First, we put the complex number in polar form by finding its modulus and Argument.  Next, we realize that we have n distinct roots; this reinforces that the index of the root is n.    We developed in class the aforementioned formula with inputs r, theta, n, and k.  

At this point, the inputs r, theta, and index are truly known; they aren't really variables in the formula any more.  The only true variable is k which counts out the various roots:  k = 0, 1, 2, ... n - 1.  This gives the function below in Maple.

> complexroots:=(r,theta,index,k)->r*(cos((theta+2*Pi*k)/index)+I*sin((theta+2*Pi*k)/index));

complexroots := proc (r, theta, index, k) options operator, arrow; r*(cos((theta+2*Pi*k)/index)+I*sin((theta+2*Pi*k)/index)) end proc

We can take this out for a "test drive" by calculating the four fourth roots of unity, i.e. the four fourth roots of the complex number 1 + 0i.  

We easily calculate the polar form in our heads:  1 is on the positive real axis.  The distance to the origin is 1; so, the modulus is 1.  The angle made between the positive real axis and the ray through the particular complex number is zero radians since they are the same ray.  We are told to calculate the fourth root; so, the index is 4.  Thus, we conclude:  r = 1, theta = 0, and index = 4.  This leaves the true variable k, and we count out the four distinct roots with k = 0, 1, 2, 3.  

We get the expected results.

> complexroots(1,0,4,0);

1

> complexroots(1,0,4,1);

I

> complexroots(1,0,4,2);

-1

> complexroots(1,0,4,3);

-I

>

The function I have given assumes you know the modulus and Argument of the complex number, i.e. have already put it in polar form.  Given what you have already learned in this handout/sheet, you know that Maple can calulate these values easily.  So, you could modify this function to calculate these two values on the fly.  Then the new/modified complexroots function would only need the a and b (from the a + bi standard form), the index of the root, and the parameter k.  You should try it out!  Make this new complexroots function with inputs a, b, index, and k!