An Introduction to Maple for MATH 205
August 1999
responsible: Thomas Riedel
1. Purpose of the document
The main purpose of this document ist to provide a common reference guide for the use of Maple in our Calculus sequence, MATH 205, 206, and 301. This introduction is intended for the instructors as well as for the students. While it is up to the instructor to do more, this is a minimal set of commands and their explanations as well as uses, thus providing a ground on which instructors in the following courses can built. When a syllabus requires MATH 205 as a prerequisite, then the instructor of that course can assume that everyone has had at least the material outlined below. This document should also help in the transition of students who took MATH 205 under the "old system" or at other institutions and are now expected to know the additional Maple material for their follow-up courses.
2. List of commands
Below is the minimal list of commands; explanations and examples follow later. This collection might seem small, but again this is only a bottom line. We provide more extensive lists at a later point in this document.
> restart;
This is one of the most important commands, it does not delete any information from the screen , but it makes the computer forget everything (including all mistakes) that you made. It is good practice to start each worksheet with this command. Note that the semicolon ; tells Maple that you are finished entering the command and that, after hitting the Enter key the computer should evaluate the expression.
a) Arithmetic
> 2+3;
> 2-3;
> 2*3;
It is important to note that the * is important, 2*3 is different from 2 3 and, naturally, different from 2 . This will become more important in the Algebra section.
> 2^3;
> 2/3;
> 2/3.0;
This brings us to one of the main features of Maple. It does exact arithmetic if you use integers, but if you use floating point numbers (those with a decimal point like 3.0 ) then it approximates. Another way of accomplishing this is
>
> evalf(2/3);
b) Algebra
As indicated above, one of the main things to remember is that the algebraic expression 2x needs to be written as 2*x
>
> 2*x+3*x;
> (x-2)*(x+2);
Maple does not automatically expand the two expressions, but the following does:
> expand((x-2)*(x+2));
> factor(x^2-4);
Another important aspect in doing algebraic manipulations is solving equations
> solve(x^2-4=0,x);
Notice there are two solutions, separated by a comma. This is the first fairly complicated command, but most of the commands listed here can be used in many ways. To find out more about a command or to get help in general you can use
> ?
This command brings up a general help sheet. To get help on a particular command, for example for help on solve use
> ?solve
One of the powerful things Maple can do is solve equations symbolically; you should remember the quadratic formula for solving
. Maple can do this:
> solve(a*x^2+b*x+c=0,x);
Solve can give some expressions which provide little or no information for Calculus:
> solve(x^4+3*x^2+x-1=0,x);
In such cases, especially if the problem is numeric, you may wish to obtain an approximate solution, here we would use
> fsolve(x^4+3*x^2+x-1=0,x,-2..-0.5);
The first entry in fsolve is the equation, the second the variable for which to solve, and the third is a range where the program should look, here in the interval [-2,-0.5].
Finally, we may wish to assign a value to a variable to evaluate an expression. This is done with the :=
> a:=3;
> a*x;
> solve(a*x^2+b*x+c=0,x);
Once you have assigned a value to a variable it retains this value until you tell Maple otherwise. Unlike in spreadsheets, this value is valid even above the line where the assignment is made and in any new worksheet that you open during this session. To tell Maple to forget the value you have to assign the varaible its original name
> a:='a';
The quotes used are the straight quotes located next to the enter key. Also be careful, the expression
> a=3;
does NOT assign a value to the variable a , (it is used to test whether a equals 3 or not).
c) Special functions
Maple knows about many functions and they do not need to be redefined. Here are some of the most used ones in Calculus
> sqrt(x);
> sin(x);
Remember that it is sin(x) in Maple not sin x .
> cos(x);
> cos(2*Pi);
> Pi;
> tan(x);
> cot(x);
> (sin(x))^2+(cos(x))^2;
> simplify(%);
The simplify command does exactly what it says. Note also that we can NOT write sin^2(x)+cos^2(x) , that would not give the same result, the parentheses are important. The other trigonometric and the hyperbolic functions work in a similar way.
Note that the exponential function is denoted differently from the ususal calculus notation:
> exp(2);
> evalf(%);
To get the value of e, we can not just type evalf(e) , but we need to use exp(1) for e.
>
> evalf(exp(1));
Of course we may wish to define e to be exp(1)
>
> e:=exp(1);
Then from now on we can use e instead of
exp(1)
and we can use
.
Also the natural logarithm is, as ususal denoted by ln, so that with our above definition
> ln(e);
> ln(e^2);
And finally there is one of the most mysterious functions to Calculus students, the absolute value function
> abs(x);
> simplify(abs(-x)-abs(x));
d) Calculus
This section contains some commands that will only make sense after the mathematics pertaining to it has been covered in class. First we start off with a simple command to plot the function
on the interval [-2,2].
> plot(2*x^2-3*x+1,x=-2..2);
> plot(abs(sin(x)),x=0..5*Pi);
Notice the inaccuracies in the graph, this is only an approximation to the "real" graph.
When dealing with functions it is convenient not to have to type the function each time it is used and to use functions as we ordinarily do in mathematics. There are many ways to define functions in Maple, we will introduce only one:
> f:=x->(x^2-4)/(x-2);
(The "arrow" is typed as a minus sign followed by a greater than sign.) This emphasizes the fact that the function f assigns to each x the value
.
> f(3);
> f(t);
> f(2*t);
> f(2t);
missing operator or `;`
This again shows that 2t is not the same as 2*t. Afurther sticky point is that
> g(x):=(x^2-4)/(x-2);
is NOT the same as f(x), note the behavior when trying to substitute values:
> g(2);
> g(2*x);
> x:=2;
> g(x);
> x:='x';
Do NOT forget to redefine x as 'x', otherwise Maple will replace all x by 2.
The limit command works as follows:
> limit((x^2-4)/(x-2),x=2);
Or we can use the function defined above
> limit(f(x),x=2);
> limit((x^2+4)/(x-2),x=2);
> limit((x^2+4)/(x-2),x=2,right);
> limit((2*x+4)/(x-2),x=infinity);
Again a ?limit will provide many examples and explanations.
To find the derivative of an expression we use
> diff(x^2-3*x,x);
> diff(sin(x),x);
> diff(sin(x^2),x);
There is a second way to get derivatives, which is useful when you wish to plot the result or get numerical values:
> h:=x->sin(2*x);
> hprime:=D(h);
> plot([h(x),hprime(x)],x=-2..1);
For integrals we can find antiderivatives
> int(-cos(x),x);
but we only get one antiderivative, namely the one without a constant. We can also find a definite integral
> int(-cos(x),x=0..3/2*Pi);
or use arbitrary boundary points
> int(-cos(x),x=a..b);
For manipulation of sums we have the sum command, but his may lead to some unexpected results:
> sum(k,k=1..n);
> sum(1/k,k=1..n);
To approximate the integral of
from 0 to 1 we would use a partition of [0,1] using n+1 points at distances
apart.
> sum((k/n)^2*1/n,k=1..n);
> limit(%,n=infinity);
> int(x^2,x=0..1);
This shows that in the limit this Riemann sum converges to the integral and it also shows the convenient shortcut of the "
(called the ditto symbol), which uses the result of the previous Maple output and puts it where the " were placed.
e) Summary
We discussed the following commands and constructs:
;
restart
+
-
*
^
/
:=
%
evalf
expand
factor
solve
?
fsolve
simplify
sqrt
sin(x)
cos(x)
Pi
exp(x)
ln(x)
abs(x)
plot
->
limit
diff
D
int
sum
Separating into categories:
Special symbols inMaple
;
+
-
*
^
:=
%
?
->
Functions and constants
sin(x)
cos(x)
exp(x)
ln(x)
sqrt(x)
abs(x)
Pi
Maple commands
evalf
expand
factor
solve
fsolve
simplify
plot
limit
diff
D
int
sum
There are many more, but these should provide sufficient material for Calculus I. Most of these commands have many more features that students should be encouraged to explore using ? and students may have to use additional commnads to complete projects. This is a minimal list and should be viewed as such. But remember we have only 14 or 15 lab hours, and the first will have to be spent on getting aquainted with the computer and the interface of Maple. After that you also should provide some of the lab time for work on projects and, possibly for some quizzes and/or tests that require the use of Maple.