Maple Examples

Below are some examples to get you started using Maple. 
The best way to learn is to try things out on your computer.

Table of Contents


Plotting a single function

To graph the function y = x^2 on the interval from -1 to 1, write this in Maple:
   plot( x^2, x = -1..1 );


Plotting two functions at once

We can plot more than one function at a time:
   plot( { sin(x), (1/3)*x }, x = -Pi..Pi );
By looking at the graph we can solve the equation sin(x) = x/3. The roots are determined by the places where the two curves cross. 
 

Equations in one unknown

To solve the equation x^3 = 27, do this:
   solve(x^3 = 27);

Note that there are three solutions, two of which are complex.
Now let's try something more complicated:
    solve(x^3 + 1.5*x = 27);
Note: There is a good reason why we wrote "1.5 " instead of "(3/2)" 
as the coefficient of x in the last equation. If one of the numbers 
in the equation is in decimal form, then Maple tries to find an 
approximate solution in decimal form. If none of the numbers are 
in decimal form, as in the first example, then Maple tries to find 
an exact solution. This may fail, since there is no algebraic formula 
for the roots polynomial equations of degree five or more.


Equations in two unknowns

We can also solve systems of equations:
   solve( { 2*x + 3*y = 1, 3*x + 5*y = 1} );
These can contain literal as well as numerical coefficients:
   solve( { a*x + 5*y = 1, 3*x + b*y = c}, { x, y } );
In the second example we have to tell Maple that x and y are the variables to be solved for. Otherwise it wouldn't know.

You can solve systems of two equations in two unknowns of the form f(x) = 0, g(x) = 0 by graphing the functions f(x) and g(x) and seeing where the curves cross.


Arithmetic

Maple does arithmetic pretty much as you would expect it to:
3*(1.3 + 1.7)^2/2 - 0.1;
It has built-in commands which can do a lot of work quickly. For example, to add up the numbers 1, 1/2, 1/3, ... 1/10, we do this:
   > sum(1/n, n= 1..10);
Note that Maple gave us the exact answer as a fraction in lowest terms. For an approximate answer in decimal form, do this:
   > sum(1.0/n, n= 1..10);
The only difference was the 1.0 in place of 1 . Note the decimal point. We can also things like factor numbers:
   > ifactor(123456789);


Algebra

Maple can do algebra:

Define p to be the square of (a + b).

   > p := (a+b)^2;
Expand it.

   > expand(p);
 

Factor this.

   > factor(a^2 + 2*a*b + b^2);

Define a to be 1.

   > a := 1;
 

Re-evaluate p.

   > p;

Define a to be a again.

   > a := 'a';
 

Now look at p again.

  > p;


Trigonometry

Maple does trigometry using radian measure.  Try these:
   > sin(Pi/2);


   > arcsin(1);
We can set things up for conversions like this:
Use evalf to convert a number to its decimal form.
   > deg := evalf(Pi/180);

 
   > rad := 1/deg;

 
   > sin(90*deg);

 
   > arcsin(1)*rad;

Next, we see that " stands for the result of the preceding computation.
Also, evalf stands for evaluate in floating point form, i.e a decimal.

   > evalf(");

Note two things. Sometimes we need to use the evalf function to convert results from exact to floating point (decimal) form. Sometimes it is convenient to use the quote(") sign: it stands for the result of the preceding computation.


Functions

You can define your own functions in Maple:
   > f := x -> sqrt( 1 + x^2 );

Evaluate the function at x=1.

   > f(1);

Evaluate the function at x=a+3.
 
   > f(a+3);
 

Functions in Maple can also have more than one variable. For example:

   > g := (x,y) -> sqrt(x^2 + y^2);

                                            

   > g(3,4);


Calculus

Maple can differentiate an expression.  Here we differentiate sin(cosx) + x^3 + 1 with
respect to x.
   > diff( sin(cos(x)) + x^3 + 1, x );
Note that the basic form of this Maple function is diff( function, variable);
It can do both definite and indefinite integrals:
   > int( x^2, x );
Note that the basic form of this Maple function is int( function, variable);
What is wrong with the answer that Maple provides?

Here is an analagous definite integral.

> int( x^2, x = 0..1);
 
Another definite integral:

 > evalf( int( sqrt( 1 + x^3 ), x = 0..1 ) );

The last computation deserves comment. Suppose we just do the obvious thing (try it!).

   > int( sqrt( 1 + x^3 ), x = 0..1 ):
Maple does not give us a numerical answer because the integral of this function cannot be expressed in terms of elementary functions. In particular it cannot be integrated by the usual techniques. However, note that we have surrounded our computation with evalf( ... ). This forces Maple to evaluate the integral numerically: evalf stands for evaluate in floating point form.

Help

For information and examples on any Maple functions or other topics, click on Help
in the upper right-hand side of the menu bar on your screen and follow the menus.
If you need information and examples on a particular Maple " function", you can bypass
the menu search by using the "?" command. For example,
   > ?solve
gives information on the solve command. Often it is helpful to scroll to the end of the help window and look at the examples, bypassing the technical discussion that precedes it.

Modified version of Maple Tutorial by the University of Utah.
Copyright © 1995 Department of Mathematics, University of Utah