Docsity

Maple Getting Started: Understanding Basic Maple Functions and Commands, Assignments of Differential Equations

Toggle sidebar
bg1
Getting Started with Maple
(September 2003)
Note: This handout is actually a "Maple Session"; everything in here was created in Maple. The actual
Maple commands that I entered are shown in the lines preceded by the ">"; these lines are immediately
followed by the resulting output.
Simple calculations:
> 2+2;
4
Note the semicolon at the end of the line. Each Maple command must end with a semicolon (or a
colon).
> (12+3*5)/4;
27
4
Note that Maple does not convert the rational number to its decimal representation. You can find the
decimal representation with the "evalf" command.
> evalf(27/4);
6.750000000
Maple has many predefined functions. For example, sine and cosine:
> sin(1.23);
.9424888019
> cos(0);
1
> cos(1);
( )cos 1
Note that Maple didn't display the numerical value of cos(1). To see the numerical value, use "evalf":
> evalf(cos(1));
.5403023059
To take a square root, you can use the "sqrt" function:
> sqrt(4);
2
Maple has several predefined constants. The one that we will need most is pi. The Maple name of pi
that can be used in an input line is "Pi". Maple is case sensitive, so the P must be a capital letter. In
the output, Maple will show the Greek letter.
> Pi;
ฯ€
> evalf(Pi);
3.141592654
1
pf3
pf4
pf5
pf8

Partial preview of the text

Download Maple Getting Started: Understanding Basic Maple Functions and Commands and more Assignments Differential Equations in PDF only on Docsity!

Getting Started with Maple

(September 2003)

Note: This handout is actually a "Maple Session"; everything in here was created in Maple. The actual Maple commands that I entered are shown in the lines preceded by the ">"; these lines are immediately followed by the resulting output.

Simple calculations: > 2+2;

4 Note the semicolon at the end of the line. Each Maple command must end with a semicolon (or a colon). > (12+35)/4;*

27 4 Note that Maple does not convert the rational number to its decimal representation. You can find the decimal representation with the "evalf" command. > evalf(27/4);

Maple has many predefined functions. For example, sine and cosine: > sin(1.23);

. > cos(0);

1 > cos(1);

cos 1 ( ) Note that Maple didn't display the numerical value of cos(1). To see the numerical value, use "evalf": > evalf(cos(1));

. To take a square root, you can use the "sqrt" function: > sqrt(4);

2 Maple has several predefined constants. The one that we will need most is pi. The Maple name of pi that can be used in an input line is "Pi". Maple is case sensitive , so the P must be a capital letter. In the output, Maple will show the Greek letter. > Pi;

ฯ€ > evalf(Pi);

> sin(Pi);

0 Another predefined constant that you will see occasionally is "I". In Maple, "I" is the square root of - (a complex number). For example: > sqrt(-1);

I > sqrt(-16);

4 I > II;*

The function name "exp" is used for the exponential function: > exp(0);

1 > exp(1);

e Note that the number "e" is displayed in the output as a boldface e. However, you should not use e^x for the exponential function; use exp(x). > evalf(exp(1));

Typically we want to do a lot more than calculate a few numbers. We want to define functions, plot graphs, solve equations, etc. We need to be able to define and store expressions in Maple. This is done with the assignment statement ":=". For example: > m := 355/113;

m :=

Now the variable "m" has been created, and it has the value 355/113. We can now use "m" in subsequent commands. > evalf(m);

> sin(m);

 

sin 355  113 The value of a variable can be an expression that is more complicated than just a number. For example, suppose we want to work with the expression 4x^2-1. We can create a variable that will hold this expression. I will call the variable "q": > q := 4x^2-1;*

q := 4 x^2 โˆ’ 1 Now there are many things we can do with this expressions. For example, we can plot it, using the "plot" command. > plot(q,x=-1..1);

We can also attempt to solve the equation 4x^2-1=0 with the "solve" command: > solve(4x^2-1=0,x);*

,

In this case, the solve command was able to find the solutions.

Let's take a closer look at the commands "plot", "diff", and "solve".

The Plot Command

The "plot" command takes several arguments, and has many options. The basic command takes two arguments. The first is the expression (i.e. function) to be plotted, and the second is the range of the independent variable of the expression. For example, the following command plots x^2 on the interval -1 < x < 1: > plot(x^2,x=-1..1);

Note that a..b is the standard method for describing a range in Maple.

We can also give a third argument to the plot command that specifies the vertical range of the plot. For example: > plot(x^2,x=-1..1,-1..1.5);

You can specify more optional arguments. In the next example, I've changed the color to black, used a dashed line, and I've given the plot a title: > plot(x^2,x=-1..1,-1..1.5,title=y=x^2,color=black,linestyle=DASH) ;

( 1 / 3 )

( 1 / 3 ) ,

( 1 / 3 )

I 3

I 3

What a mess! If you look carefully at the above output, you will see that Maple has found three solutions, two of which are complex numbers. (Recall that the symbol I in Maple is the complex number sqrt(-1).)

What happens if the equation has no solution, or if Maple can not find it? Here are some examples. First, a trivial example with no solution: > solve(1=0,x);

Maple gave no output; this means that either there is no solution, or Maple can not find any solutions.

Note that Maple can solve an equation like x^2=-1, because Maple allows complex numbers: > solve(x^2=-1,x);

I , โˆ’ I Sometimes Maple gives a partial solution: > solve(x(sin(x)+x+1/4)=0,x);*

0 , RootOf( 4 _Z + 4 sin( _Z )+ 1 ) The "RootOf" function means the root of the expression; in the expression, _Z is the variable. In this example, Maple found one solution to be 0, but the other "solution" is just the solution to 4_Z + 4sin(*_Z) +1=0. Maple could not find an analytical solution to this equation.

Let's create a function, plot it, and then use "diff" and "solve" to find the critical points.

> w := (x^4+3x^2)/(1+x^4);*

w :=

x^4 + 3 x^2 1 + x^4 > plot(w,x=-3..3);

> dw := diff(w,x);

dw := โˆ’

4 x^3 + 6 x 1 + x^4

4 ( x^4 + 3 x^2 ) x^3

( 1 + x^4 )

2

> plot(dw,x=-3..3);

> solve(dw=0,x);

0 , โˆ’ , , ,

Note that two of the five solutions found by "solve" are actually complex numbers.