You are on page 1of 34

An Introduction to Maple

Students Manual
Prepared by
Dr. Faruk Uygul
Department of Mathematics and Statistics
American University of Sharjah
Fall 2011
1
Table of Contents
Introductory Remarks. 3
Chapter 1. Packages, Commands, and Functions... 4
Packages 4
Commands 6
a) Factorization... 6
b) Expansion... 6

c) Simplification. 6
d) Substitution 7
Functions.. 7
a) Absolute value function..... 7
b) Square root function.. 8
c) Logarithmic functions 8
d) Exponential functions 8
e) Trigonometric functions 9
f) Greatest integer function.... 9
Defining New Functions.. 9
Defining Functions with Several Variables. 11
Chapter 2. Calculation of Limits. 12
Chapter 3. Linear and Non-linear Equations 14
Chapter 4. Differentiation. 17
Chapter 5. Integration 20
Chapter 6. Graphs and Animations 24
Graphs in 2-d... 24
Graphs in 3-d 28
Animations... 31

2
Introductory Remarks
The purpose of this document is to give Calculus I students a short introduction to Maple.
After reading this manual and doing the projects provided, you will have a better
understanding of the concepts you will be learning in class.
Maple is a software which is used worldwide and can be run on different operating
systems, including Unix and Windows. Maple is a very helpful tool in learning different
areas of mathematics. It allows us to perform mathematical calculations, graph functions,
solve equations, etc. You can use the commands defined in Maple to perform certain
calculations, and you can create loops to define new commands too. Therefore, Maple
can also be used as a programming language.
The following manual will introduce you to some basic features of this mathematical
software and will provide you with useful examples. Throughout the semester, you will
be assigned projects that will allow you to practice in Maple what you have learned in
class.
Note that this document is color coded: the fonts in red are Maple commands and the
fonts in blue are Maple outputs of commands.
3
Chapter 1. Packages, Commands, and Functions
Packages
In order to conserve memory, Maple uses the concept of packages. A Maple package is a
collection of related Maple commands. Note that certain commands work only with
certain packages. In order to load a package, use the command
with(packagename)
Some packages available with Maple 12 are listed below.
numapprox numerical approximation
combinat combinatorial functions
DEtools differential equation tools
difforms differential forms
Gauss create domains of computation
GaussInt Gaussian integers
geom3d three-dimensional Euclidean geometry
geometry two-dimensional Euclidean geometry
grobner Grobner bases
group permutation and finitely-presented groups
liesymm Lie symmetries
linalg linear algebra
logic Boolean logic
networks graph networks
np Newman-Penrose formalism
numtheory number theory
orthopoly orthogonal polynomials
padic p-adic numbers
plots graphics package
powseries formal power series
projgeom projective geometry
simplex linear optimization
stats statistics
student student calculus
totorder total orders on names
In order to get help on a certain package, type
?packagename
4
Example:
with(student);
D Diff Doubleint Int Limit Lineint Product Sum Tripleint changevar , , , , , , , , , , [
completesquare distance equate integrand intercept intparts leftbox leftsum , , , , , , , ,
makeproc middlebox middlesum midpoint powsubs rightbox rightsum , , , , , , ,
showtangent simpson slope summand trapezoid , , , , ]
We use
restart to clear up the memory
; to execute a command
: to execute a command but hide its output
:= to define a constant
shift+enter to type more than one command line without executing them
Example:
x:=1; y:=7; z:=-5;
:= x 1
:= y 7
:= z -5
x+y; y*z;
8
-35
Some elementary operators are as follows:
>, <=, >=, *, +, =, -, /, ^
Example:
(5-3)*7;
14
17>=8;
8 17
5
Commands
Now let us look at some fundamental commands.
a) Factorization
factor(expression), ifactor(integer)
Example:
factor(x^2-y^2);
( ) x y ( ) + x y
factor(x^3-y^3);
( ) x y ( ) + + x
2
x y y
2
ifactor(105985486540);
( ) 2
2
( ) 5 ( ) 73 ( ) 2411 ( ) 30109
We can also perform complex factorization. In the example below, I stands for the
complex number i.
Example:
factor(x^2+y^2,I);
( ) + x y I ( ) + x y I
b) Expansion
expand(expression)
Example:
expand((x-y^3)*(5*x-y+1));
+ + 5 x
2
x y x 5 y
3
x y
4
y
3
c) Simplification
simplify(expression)
6
Example:
simplify(sin(x)^2+cos(x)^2);
1
simplify(81^(1/4));
3
In the following expression, we assume that x is negative.
simplify(sqrt(x^2)+abs(x), assume=negative);
2 x
d) Substitution
We use the following command to substitute a value for a variable in an expression.
subs(variable=value, expression)
Example:
A:=x^7-3*x+1;
:= A + x
7
3 x 1
subs(x=5,A);
78111
Functions
Now let us consider some fundamental functions that are used in Calculus.
a) Absolute value function
abs(expression)
Example:
abs(-2)+abs(-56);
58
7
b) Square root function
sqrt(expression)
Example:
sqrt(64);
8
sqrt(a^3)+sqrt(b^7);
+ a
3
b
7
c) Logarithmic functions
ln(expression), log(expression), log[a](expression)
Example:
log(100);
2 ( ) ln 10
log[3](80);
( ) ln 80
( ) ln 3
In the following example, we get a numerical value:
evalf(log[5](256));
3.445412466
d) Exponential functions
exp(a)
Example:
e:=exp(1);
:= e e
ln(e);
1
expand(exp(x+y)-56*x);
e
x
e
y
56 x
8
e) Trigonometric functions
sin(x), cos(x), tan(x),ctn(x),sec(x),csc(x),
arcsin(x), arccos(x), arctan(x),arcctn(x),arcsec(x),arccsc(x)
Example:
sin(Pi);
0
arcsin(1/2);

6
cos(Pi/7);

_
,

cos

7
f) Greatest integer function
floor(x)
Example:
floor(2.6);
2
floor(-1.1);
-2
Defining New Functions
There are different ways of defining a new function in Maple. For this purpose, we can
use
f:=function or g:=x -> function
Example:
f:=x^3-exp(x)+1;
:= f + x
3
e
x
1
9
Now, let us evaluate this function at x=2:
subs(x=2,f);
9 e
2
For the numerical value of this expression type:
evalf(%);
1.610943901
Example:
g:= x -> x^3-ln(x)+2^x;
:= g x + x
3
( ) ln x 2
x
g(3);
35 ( ) ln 3
evalf(%);
33.90138771
Example (defining a piecewise-defined function):
Now we define the following function
( ) g x {
x
2
68 x < x 0
+ 2 x 1 < 0 x
g:=x->piecewise(x<0, x^2-68*x, x>0, 2*x+1);
:= g x ( ) piecewise , , , < x 0 x
2
68 x < 0 x + 2 x 1
g(3);
7
Now we define the following function
( ) f x {
1 x 0
2 otherwise
f:=x -> piecewise(x <>0,1,2 );
:= f x ( ) piecewise , , x 0 1 2
f(0);
2
10
Defining Functions with Several Variables
Example:
f:=(x,y,z)-> x^2-x*y+y*z;
:= f ( ) , , x y z + x
2
x y y z
f(1,2,6);
11
f(a,b^2,c^3);
+ a
2
a b
2
b
2
c
3
As it is seen in the previous example, Maple can perform symbolic calculations.
11
Chapter 2. Calculation of Limits
We use the command
limit(f(x),x=a)
to calculate the limit of a function f(x) as x tends to a. Similarly, for one-sided limits we
use the following commands:
limit(f(x),x=a,right), limit(f(x),x=a,left)
Example:
f:=(x)-> exp(x)+x^2-1;
:= f x + e
x
x
2
1
limit(f(x), x=4);
+ e
4
15
Example:
limit(sin(x)/x, x=0);
1
Example:
f:=(x)-> piecewise(x<0, 1-2*x, x>=0, 1*2*x^2);
:= f x ( ) piecewise , , , < x 0 1 2 x 0 x 2 x
2
limit(f(x), x=0);
undefined
Example:
g:=(x)-> floor(x);
:= g x ( ) floor x
limit(g(x),x=2,left);
1
limit(g(x),x=2,right);
2
limit(g(x),x=2);
undefined
12
Example:
If the limit of f(x) at a does not exist but the function is bounded in [m,M] around a, then
Maple returns [m,M] as the value of the limit.
limit(7*sin(1/x),x=0);
.. -7 7
Example (limits at infinity):
f:=x -> (-2*x^5-6*x^2+1)/(8*x-7*x^5);
:= f x
+ 2 x
5
6 x
2
1
8 x 7 x
5
limit(f(x),x=infinity);
13
2
7
Chapter 3. Linear and Non-linear Equations
The command
solve(equation,variable)
is used to solve a given equation with respect to the indicated variable.
Example:
solve(x^2=4,x);
, 2 -2
Example:
solve(x*y^2+x+y=1,x);

y 1
+ y
2
1
solve(x*y^2+x+y=1,y);
,
+ 1 + 1 4 x
2
4 x
2 x

+ 1 + 1 4 x
2
4 x
2 x
Example:
solve(x^2+x-4=0,x);
, +
1
2
17
2

1
2
17
2
Example:
The equation might have complex solutions:
solve(3*x^2-6*x+6=0,x);
, + 1 I 1 I
Example:
Maple can solve symbolic equations:
solve(A*x^2+B*x+C=0,x);
14
,
B B
2
4 A C
2 A

+ B B
2
4 A C
2 A
Example (trigonometric equations):
solve(sin(2*x)=cos(x),x);
, , ,

6
5
6

2
Example:
The equation to be solved can be defined first:
f:=x -> sin(3*x);
:= f x ( ) sin 3 x
solve(f(x)=1,x);

6
If one does not need an exact or a symbolic solution, the command
fsolve(equation,variable)
can be used to solve equations.
Example:
fsolve(3*cos(x)=x,x);
-2.938100394
Compare it to
solve(3*cos(x)=x,x);
( ) RootOf _Z 3 ( ) cos _Z
Example:
fsolve(a*tan(x)=x,x);
Error, (in fsolve) a is in the equation, and is not solved for
There is an error message since fsolve cannot handle symbolic equations.
15
Example (separating the solutions of an equation):
solns:=solve(2*x^2-3*x+1=0,x);
:= solns , 1
1
2
solns[1]; solns[2];
1
1
2
Example (solving an equation with several variables):
solve(x^2+y^2-3*x+y+1=0,{x,y});
, { } , x +
3
2
5 4 y
2
4 y
2
y y { } , x
3
2
5 4 y
2
4 y
2
y y
16
Chapter 4. Differentiation
The command
diff(expression, variable)
is used to differentiate an expression with respect to a variable.
Example:
diff(4*x^3+3*x-1,x);
+ 12 x
2
3
diff(sin(x)-cos(2*x),t);
0
Example (differentiating piecewise-defined functions):
First, we will differentiate
( ) f x {
x
2
x 0
x
3
< 0 x
f:=x->piecewise(x<=0,x^2,x>0,x^3);
:= f x ( ) piecewise , , , x 0 x
2
< 0 x x
3
diff(f(x),x);
{
2 x x 0
3 x
2
< 0 x
Now, we will differentiate
( ) g x {
( ) sin 2 x
2
x 0
( ) tan x < 0 x
g:=x->piecewise(x<=0,sin(2*x^2),x>0,tan(x));
:= g x ( ) piecewise , , , x 0 ( ) sin 2 x
2
< 0 x ( ) tan x
diff(g(x),x);

'
4 ( ) cos 2 x
2
x < x 0
undefined x 0
+ 1 ( ) tan x
2
< 0 x
17
Higher order derivatives can be calculated by the same command. For example,
diff(f(x),x$n)
calculates the n
th
derivative of the function f(x).
Example:
f:=x->x^5-4*x^(-4)+sin(x);
:= f x + x
5
4
x
4
( ) sin x
diff(f(x),x$2);
20 x
3
80
x
6
( ) sin x
diff(f(x),x$7);

2419200
x
11
( ) cos x
The following example calculates some partial derivatives of a given function.
Example:
f:=x^5+4*y^(2)+2^(x*y*z)+ln(x+2*z);
:= f + + + x
5
4 y
2
2
( ) x y z
( ) ln + x 2 z
diff(f,z);
+ 2
( ) x y z
x y ( ) ln 2
2
+ x 2 z
diff(f,z,y);
+ 2
( ) x y z
x
2
z ( ) ln 2
2
y 2
( ) x y z
x ( ) ln 2
Example (finding the critical numbers of a function):
We will find the critical numbers of ( ) f x + 3 x
3
4 x
2
x 1
.
f:=x->3*x^3-4*x^2+x-1;
:= f x + 3 x
3
4 x
2
x 1
18
CriticalNumber:=solve(diff(f(x),x)=0,x);
:= CriticalNumber , +
4
9
7
9

4
9
7
9
CriticalNumber[1];
+
4
9
7
9
CriticalNumber[2];

4
9
7
9
19
Chapter 5. Integration
We use the command
int(function, variable)
to evaluate the indefinite integral of a function with respect to its variable. In the output,
the arbitrary constant is chosen as zero.
The command
Int(function, variable)
displays the integral notation. Note that we load the package "student" to use this
command.
Example:
with(student);
D Diff Doubleint Int Limit Lineint Product Sum Tripleint changevar , , , , , , , , , , [
completesquare distance equate integrand intercept intparts leftbox leftsum , , , , , , , ,
makeproc middlebox middlesum midpoint powsubs rightbox rightsum , , , , , , ,
showtangent simpson slope summand trapezoid , , , , ]

int(x*exp(x),x);
( ) + 1 x e
x
Int(x*exp(x),x);
d

(
(
x e
x
x
We can define the integrand function first. This is illustrated in the following example:
Example:
with(student):
f:= x->ln(x)+tan(x)-3^x;
:= f x + ( ) ln x ( ) tan x 3
x
int(f(x),x);
x ( ) ln x x ( ) ln ( ) cos x
3
x
( ) ln 3
20
If the Int(function, variable) command is to be used, we can evaluate the integral by
value or value(%) commands.
Example:
f:= x->sqrt(x^2+4)+cot(x)+5^x;
:= f x + + + x
2
4 ( ) cot x 5
x
Int(f(x),x);
d

(
(
+ + + x
2
4 ( ) cot x 5
x
x
value(Int(f(x),x));
+ + +
x + x
2
4
2
2

_
,

arcsinh
x
2
( ) ln ( ) sin x
5
x
( ) ln 5
value(%);
+ + +
x + x
2
4
2
2

_
,

arcsinh
x
2
( ) ln ( ) sin x
5
x
( ) ln 5
Example (defining an antiderivative):
f:= x->exp(x)+3*cos(x)+tan(5*x);
:= f x + + e
x
3 ( ) cos x ( ) tan 5 x
Int(f(x),x);
d

(
(
+ + e
x
3 ( ) cos x ( ) tan 5 x x
value(%);
+ + e
x
3 ( ) sin x
1
10
( ) ln + 1 ( ) tan 5 x
2
F:=unapply(%,x);
:= F x + + e
x
3 ( ) sin x
1
10
( ) ln + 1 ( ) tan 5 x
2
F(5);
+ + e
5
3 ( ) sin 5
1
10
( ) ln + 1 ( ) tan 25
2
21
We use the command
int(function, x=a..b)
to evaluate the integral of a function on the interval [a,b].
The command
Int(function, x=a..b)
displays the integral notation.
Example:
f:= x->6*x^(-3)+arcsin(x)+x+1;
:= f x + + +
6
x
3
( ) arcsin x x 1
Int(f(x),x=1..5);
d

(
(
(
(
1
5
+ + +
6
x
3
( ) arcsin x x 1 x
int(f(x),x=1..5);
+ +
472
25
2 5 I ( ) ln + 5 2 6 2 I 6
In some cases, evaluating the antiderivative function might be difficult. However, the
numerical integration is always possible.
Example:
int(exp(sin(x)),x=1..3);
d

(
(
1
3
e
( ) sin x
x
evalf(%);
4.424799927
Example (definite integral with unbounded boundaries):
Int(1/(x+1)^2,x=1..infinity);
22
d

(
(
(
(
1

1
( ) + x 1
2
x
int(1/(x+1)^2,x=1..infinity);
1
2
23
Chapter 6. Graphs and Animations
Maple can be used to sketch graphs of functions in 2-d or 3-d in various coordinate
systems. It can also be used to create animations. The graphs or the animations can be
exported as bmp or gif files. You can always change the properties of a graph by right
clicking on it.
Graphs in 2-d
The command
plot(function,x=a..b)
is used to sketch the graph of f(x) on the interval [a,b].
Example:
plot(x,x=-2..2);
24
Example (point style graphing):
plot(f(x),x=-2..2, style=point);
Example (colored graphs):
plot(x^3,x=-1..1, color=green);
Example (graphs of piecewise defined function):
Now let us consider
( ) f x

'
3 x x -2
2 x and < -2 x x 2
+ x
2
4 x 3 < 2 x
25
f:=x-> piecewise(x<=-2,-3-x,-2<x and x<=2,2*x,x>2,x^2-4*x+3);
:= f x ( ) piecewise , , , , , x -2 3 x and < -2 x x 2 2 x < 2 x + x
2
4 x 3
Now compare the following two graphs:
plot(f(x),x=-4..4);
plot(f(x),x=-4..4,discont=true);
The thickness of a graph can be changed as it is seen in the following example:
26
Example:
plot(f(x),x=-40..100, thickness=3);
Example (two graphs on the same diagram):
plot([sin,cos],-Pi..Pi,legend=["y=sin(x)","y=cos(x)"],title="Some Trigonometric
Functions");
27
Example (two perpendicular lines on the same diagram):
f:=(-8/13)*x+2; g:=(13/8)*x-1;
:= f +
8 x
13
2
:= g
13 x
8
1
plot([f,g],x=-1..5,legend=["y=f(x)","y=g(x)"]);
Graphs in 3-d
Use the command
plot3d(function,x=a..b, y=c..d)
to sketch the graph of z=f(x,y) over the indicated intervals.

28
Example:
plot3d(x^2+y^2,x=-4..4,y=-4..4);
plot3d(sin(x*y),x=-1..1,y=-1..1);
Example (graph of a function in spherical coordinates):
plot3d((1.3)^x*sin(y),x=-1..2*Pi,y=0..Pi,coords=spherical,style=patch);
29
Example (graphing by contours):
plot3d(cos(x*y),x=-Pi..Pi,y=0..Pi,style=contour);
Apart from the usual Cartesian coordinates, the best-known and most widely used
coordinates are the polar coordinates. Use the command
polarplot(function, theta=a
1
..a
2
)
to sketch the graph of a polar function r(theta) when theta is in the indicated interval. In
order to use this command, you must load the package plots.
Example (the circle given by r(theta) = 1):
with(plots):
polarplot(1);
30
Example:
polarplot(theta, theta=0..4*Pi);
Example (two polar curves on the same diagram):
polarplot([[t,t,t=-2*Pi..Pi],[2*cos(t)^2,2+sin(t),t=-
2*Pi..Pi]],numpoints=500,color=["Red","Blue"]);
Animations
The command
animatecurve(function, range)
animates the graph of a given function over the given horizontal range.
31
Example:
with(plots):
animatecurve(sin(x),x=-Pi..Pi,frames=500);
Example (animating two functions simultaneously):
animatecurve({sin(x),cos(x)},x=-2*Pi..2*Pi,frames=100);
Use the command
animate(plotcommand, plotargs, t=a..b, options)
to animate a 2-d or a 3-d graph on one variable. Here, plotcommand is the command line
that generates the 2-d or the 3-d graph. This command is very useful when one wants to
see a family of curves on the same diagram.
32
Example:
animate(plot,[A*x^2,x=-15..15],A=-10..10);
Example:
animate(plot3d,[A*(2*x^3+y^2),x=-3..3,y=-3..3],A=-2..4);
Example (an application to continuity):
Consider the function
:= ( ) F x {
+ + x
2
2 x c x 1
+ 2 x
2
3 x 2 c < 1 x
F(x):=piecewise(x<=1,x^2+2*x+c,x>1, -2*x^2-3*x+2*c);
:= ( ) F x {
+ + x
2
2 x c x 1
+ 2 x
2
3 x 2 c < 1 x
33
F:=x->piecewise(x<=1,x^2+2*x+c,x>1, -2*x^2-3*x+2*c);
:= F x ( ) piecewise , , , x 1 + + x
2
2 x c < 1 x + 2 x
2
3 x 2 c
LL:=limit(F(x),x=1,left);
:= LL + 3 c
RL:=limit(F(x),x=1,right);
:= RL + 5 2 c
solve(LL=RL,c);
8
with(plots):
animate(plot,[F(x),x=-4..4,discont=true],c=-19..19);
34

You might also like