Professional Documents
Culture Documents
MAPLE MANUAL
Introduction:
Maple is the essential technical computing software for today’s engineers, mathematicians, and
scientists. Whether you need to do quick calculations, develop design sheets, teach fundamental
concepts, or produce sophisticated high -fidelity simulation models, Maple’s world -leading computation
engine offers the breadth and depth to handle every type of mathematics.
Maple combines the world’s most powerful mathematical computation engine with an intuitive,
“clickable” user interface. Its smart document environment automatically captures all of your technical
knowledge in an electronic form that seamlessly integrates calculations, explanatory text and math,
graphics, images, sound, and diagrams.
MAPLE Tutorial:
Every Maple command is next to a prompt (the greater than sign >), and every Maple command must be
terminated by a semicolon or colon. The semicolon tells Maple to print the result of the command, the
colon tells Maple not to print the command's result.
A Maple command can contain a comment that is not really part of the command. A pound sign (i.e. #) as
part of a line of Maple input means a comment that Maple should ignore.
> 4+4; # Maple ignores wha t comes after the pound sign.
1/3 +1/3;
1.0/3 +1/3; answer is incorrect use evalf for approx
evalf(1/3 +1/3);
sqrt(24); leaves the answer in exact form
sqrt(24.0); Or use evalf
4*(3+Pi);
100!;
length( % ); Maple can determine the num ber of digits in a large number
0.3463678+1.7643
Converting rational
Convert(%,’rational’) or
convert(ctrl+L,’rational’) enter the equation when ctrl+L window activate
1
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
Trigonometric functions
sin(5*Pi/3); evalf(%);
tan3(Pi/3); sec(Pi/4); arcsin(-1);
ilcm(-10,6,-8);
max(3/2 , 1.49);
min(3/5, ln(2), 9/13, - ∞);
seq(k^2,k=1..100);
Assigning variables
Using assignment operator : =
k := 3/5+5/9+7/12;
evalf(k);
evalf(k,3);
2
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
j := 2^5;
sqrt(j);
w := 4*(3+Pi);
evalf(w,4);
result := seq(sqrt(k),k=1..10);
evalf(result);
Pi;
evalf(%);
%+5;
Warning: Use of % should be avoided as much as possible, as it may make the worksheet unreadable.
Clearing Variables
Using command
Restart; OR unassign('x'); OR x := 'x';
Vectors
A vector in Maple is a one-dimensional array whose indices start from 1. The vector() function is used to
define a vector in Maple. It is part of the linalg package. There are several ways to define a vector:
1. vector([x1,x2...xn]) or vector(n, [x1,x2,...xn]);
Creating a vector of length n
containing the given elements
x1,x2,...xn .
2. vector(n);
Creating a vector of length n with unspecified elements.
#load the package
Vector Algebra
The commonly used algebra operations on vectors are as follows:
A:= Vector(3,[1,2,3]);
B:= Vector(3,[-4,-2,-1]);
2*A;
3
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
-3*B;
A-B
A+B
DotProduct(A,B);
CrossProduct(A,B);
Matrices
A matrix in Maple is a two-dimensional array with row and column indices starting from
1. Matrices are defined in two ways:
A:=Array(1..m,1..n); # A matrix with m rows and n columns
A:=Matrix(m,n,[..list f elements..]); #a matrix with m rows and n columns with specified
elements
The function Matrix() is part of the LinearAlgebra package.
A:= Matrix(2,2,[1,3,4,6]);
Matrix Algebra
* Sign
4
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
W := 3*x^2+8;
eval(3*x^2+8,x=4); evaluating the expression where x has the value 4
OR
eval(W,x=4);
M := eval(W,x=5+2*u);
expand(M);
Notice that, unlike the eval command, subs did not simplify the result so we also need to use simplify.
simplify( % ); evalf( % );
f := exp(sqrt(t))*(1+arcsin(sec(t)));
eval( f, t=ln(2) );
evalf( % );
(Notice that the answer is a complex number. I is Maple's notation for 1 .)
Function Vs Expression
Function is defined by:
f := x -> cos(Pi*x)+3;
Take note of the syntax here. The "arrow" is necessary, and is made by typing (with no
intervening space) a "minus sign" and a "greater than" symbol.
f(x) := cos(Pi*x)+3;
or
5
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
f := cos(Pi*x)+3;
The first input fails to define the desired function because of the assignment to the symbol . In
general, this kind of assignment should be avoided in Maple.
Putting values
f(-1);
f(2+sqrt(5));
evalf(f(2+sqrt(5)));
f(x+4);
simplify(f(x+4));
6
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
Expression
H := 2*(x-2)*(2*x^2+5*x+2)*(x+4);
ans := expand(H);
factor(ans); different from original expression bcoz it factorizes 2x 2+5x+2
Trigonometric expressions
V := cos(x)^5+sin(x)^4+2*cos(x)^2 -2*sin(x)^2-cos(2*x);
simplify(V);
Normal Function
If an expression contains fractions, it may be useful to restructure the expression as a large
fraction by canceling out common factors in the numerator and denominator. The normal
function implements this process.
normal(x5/(x+1)+ x4/(x+1));
7
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
solve( 5*x+3=2, x );
Maple tells us what value of x solves the equation. You may wonder why we need to tell Maple to solve
for x when in fact x is the only variable in the equation. But it may be that the equation has several
variables, so we always need to tell Maple what var iable to solve for. For example,
solve(4-v=2*T-k*g,g);
g = solve(4-v=2*T-k*g,g);
solve( a*x+b=c, x );
solve( a*x+b=c, b );
eqn1 := a*x^2+b*x+c=0;
Notice how there are two distinct kinds of "equal signs" in the above command, one is the assignment
operator and the other is part of the equation. The first "equal sign" says that eqn1 is a name for
a*x^2+b*x+c=0. The second "equal sign" asks if the left hand side of the equation is equal to the right
hand side.
solve( eqn1, x );
a := 1; b := 2; c := -1; substitute values in quadratic equation
eqn1;
The name solution now refers to both of the solutions! Here is how we can give a name to each
individual solution.
solution[1];
solution[2];
Suppose we want to check that these solutions really do solve the quadratic.
eq := x^3-5*x^2+23=2*x^2+4*x-8;
lhs(eq);
rhs(eq);
eqn2 := lhs(eq)-rhs(eq)=0;
8
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
eqn3 := x^3-34*x^2+4=0;
H := solve(eqn3,x);
sol := evalf(H);
Note that the I stands for . When a solution is this complicated it is more useful to look at the
approximate solutions using evalf command.
The small imaginary part attached to each real root can be removed with the fnormal command.
fnormal([sol]);
simplify(fnormal([sol]));
fsolve(eqn3,x);
Maple's fsolve command will compute a numerical approximation for each solution of a polynomial
equation.
eqn := x^4-x^3-17*x^2-6*x+2=0;
fsolve(eqn,x);
eqn1 := 2*x+4*y=6;
eqn2 := -x+5*y=1/2;
We shall ask Maple to solve this system of equations, then give the solution a name and
compute a decimal approximation of the solution. Notice the way the solve command is
written here, using braces around the equat ions and the variables.
Notice that the variables x and y still do not have values. (Those are not assignment operators inside the
braces.)
x; y;
The solve command found the values of x and y that satisfy the equations, but the solve
command does not give x and y those values. The assign command is used to assign the values from
the solution to the variables.
assign( answer );
x; y;
9
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
We have seen several examples of how Maple can solve equations symbolically. After we have computed
the answer symbolically, we can always use the evalf command to find a numeric approximation of
the solution. However, there are equations that Maple cannot solve symbolically and in those cases we
can only calculate numeric approximations of a solution. Let us look at an example. Here is a fairly
complicated equation. We shall give it the name eqn3.
eqn3 := -2+exp(t)=sin(t^2);
solve( eqn3, t );
Not a very useful answer. (Look at the answer very carefully. Can you make sense out of it? Is it
really "the solution" of the equation?) So let us use the fsolve command to tell Maple to solve
this equation numerically.
Why is this command called "fsolve" and not "solvef"? the evalf and fsolve commands they are
described respectively as "evaluate using floating -point arithmetic" and "solve using floating -point
arithmetic". So it would seem that their names should be more consistent.
We still cannot tell if these are the same number. So find their decimal values.
10
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
Instant Solution
(x-7)2+(x-1)2 = 4((x-1)2+(x-4)2)
Right click the expression and select Solve -> Solve for variable->x
Graphical Solution
(x-7)2+(x-1)2 = 4((x-1)2+(x-4)2)
Write expression and then enter.
Right click the output , select Move to Left, right click the output and select Left hand side. Right click
the output and select Expand.
Ctrl+drag the eq into new document block , right click, select Plots-> 2-D Plot.
Right click the plot and select Axes-> Properties. In the Horizontal tab, de-select Use data extends,
change the range 0 and 5. Similarly vertical tab change -5 to 10.
Graphical Solution
Write equation, then press enter button, right click select left hand side, right click select plots -> plot
builder.
Modify plot range 0 to 2*Pi
When a system has more variables than equations we often get not one, but an infinite number of
solutions.
11
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
Now let's look at the solution that is generated when we take x=1,2,3 and 4
eval(soln,x=1);
eval(soln,x=2);
eval(soln,x=3);
eval(soln,x=4);
diff( g(x)*h(x), x );
diff( g(x)/h(x), x );
simplify( % );
Maple uses the same command, diff, for computing partial derivatives.
diff( g, x );
diff( g, y );
We can compute higher order partial derivatives. Here are all four of the second order partial
derivatives.
diff( g, x,x );
diff( g, y,y );
diff( g, x,y );
diff( g, y,x );
example:
f := x^2*sin(3*x);
diff( f, x );
diff( f, x,x ); Second Derivative
We can compute any order of derivative that we want, computing the 7th derivative.
diff( f, x$7 );
By using interactive
Question:
f(x)=xcos(x)
graph: f, f’, f”
-Pi to Pi
Solution:
x*cos(x)
12
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
now format menu Create Document Block .Ctrl+drag the original expression to the new document
block. Right click the expression and select Differentiate -> x.
now again go to format menu create doc block. Ctrl+drag the derivated expression, right click and
select Differentiate -> x.
Ctrl+drag the expression new document block, right click and select plots-> plot Builder.
In the interactive Plot Builder: Select Plot Type dialog, change x-axis range –Pi..Pi
High light the other derivative and ctrl+drag and plot them or u can simply drop these ex pression the
graph
Add a Legend
Right click in the plot region select Legend -> Show legend
Add a Title
Click the drawing I con in the toolbar Click T in the drawing menu.
Click the plot region the text will appear
Solution By Tutor:
Tools->Load Pacakage-> StudentCalculus1
x*cos(x)
right click the expression, select tutor ->calculus-single variable-> Derivatives
change the different options and click Display and then close
Antiderivatives
int( x*ln(x), x );
Notice that Maple does not put a +C at the end of its antiderivatives. You are expected to know that they
really are supposed to be there.
Maple has a slight variation on the int command. The Int command is called the inert form of int. The
inert form of a Maple command does not do any calculation. Instead, it typesets a formula for us.
Int( x*ln(x), x );
We can use the inert form of a Mapl e command to get nice looking formulas like the following.
13
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
Symbolic Summation
sum( i, i=1..n );
factor( % );
Sum( i^2, i=1..n ) = sum( i^2, i=1..n );
GRAPHING CALCULATION
Tools->Assistants->plot builder.
Add expressions
X^2+1
Cos(x)+1
Ok
Another way
Write expression on document mode
e.g x^2
right click on the expression, select plots -> plot builder.
Another way
plot( x^2, x=-5..5 );
We give the plot command the formula that we want to graph and then tell it what interval of
numbers to draw the graph over.
plot( sin(x), x=-2*Pi..2*Pi );
Maple can even plot graphs from negative infinity to infinity. This is useful when we want an
overall idea of what a graph looks like without having to guess at an appropriate domain.
g := (x^2+3*x)/(x^4+x+1);
plot( g, x=-infinity..infinity );
plot( x^2, x=-infinity..infinity );
plot(sin(x), x=-infinity..infinity );
We can also control the range used on the vertical axis of a graph.
14
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
f := x^3-x;
plot( f, x=-5..5 );
plot( f, x=-5..5, -10..10 );
More than one functions at a time by putting a list of functions inside a pair of brackets.
plot( [sin(x), cos(x)], x=0..2*Pi );
TITLE Option
plot( 4*x*(1-x), x=0..1, title="The logistic map." );
pict1 := plot([-3*x+5,9-x^2],x=-3..5,color=[green,red]):
pict2 := plot([[-1,8],[4,-7]], style=point,color=blue, symbol=circle):
display([pict1,pict2]);
Interactive Command
The interactive command is part of the plots package. It allows you to build plots interacti vely by
opening a window where you can specify details.
Plots[interactive](sin(x)+1);
Or
interactive(sin(x)+1);
Select 2-D Plot, try different options for line style, axes, or color as well.
15
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
Parametric Equations
Maple's plot command can also be used to graph curves described by parametric equations.
To graph the parametric curve corresponding to the pair of parametric equations: and on
the parameter interval use the command:
plot([t^2-t,2*t-t^3,t=-2..2],x=-2..5,y=-5..5);
When the range is inside the brackets, Maple is graphing the parametric curve but when the range is
outside the brackets, Maple is graphing two separate functions.
more interesting parametric curve.
plot( [t+2*sin(2*t), t+2*cos(5*t), t= -2*Pi..2*Pi] );
Implicit Plots
Maple can plot curves that are implicitly defined by an equation in the variables x and y.
The implicitplot command computes the two-dimensional plot of an implicitly defined curve. By
default, the curve is computed in Cartesian coordinates.
Recall that this is the equation of an ellipse with the lengths of major and minor axes equal to 10 and 6
respectively.
Our first attempt at getting the expected graph comes up short !
implicitplot(x^2/25+y^2/9=1,x= -5..5,y=-5..5);
The problem here is that the x- and y-scales are not equal. To force equal scaling add
"scaling=constrained" or click on the graph to expose the graphing toolbar, and select the button marked
1:1.
The graph then appears as seen in the following figure.
implicitplot(x^2/25+y^2/9=1,x= -5..5,y=-5..5,scaling=constrained);
16
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
Polar Graphs
Graphs of polar equations are handled by the polarplot command, which is part of the plots
package accessed using with(plots).
For example, to graph 1+cos( ) in polar coordinates using the plot command, type:
plot(1+cos(theta),theta=-Pi..Pi,coords=polar);
Be sure to click on the above graph and try moving it around with the mouse button pressed down. Here
are a few more examples.
Maple can also graph parametric surfaces in space. Here is a sphere graphed as a parametric
surface (in rectangular coordinates).
Cylindrical coordinates
Here is a demonstration of cylindrical coordinates.
plots[coordplot3d]( cylindrical );
17
3-Days Workshop at HPCC Presented by: Ms. Nida Fouq, ITM, HPCC , NEDUET
Animation
Animation displays a number of frames in sequence. There are two basic animation functions defined in
Maple. They are animate and animate3d.
Before using them, we must load the plots package via the command with(plot).
Two-dimensional Animation
animate() is used for two-dimensional animation. It has one frame variable, t, and one
dependent variable, x. The frame variable t changes for each fra me and the dependent
variable x defines the function argument range in each frame.
The next animation also has a lot of frames and it runs for a fairly long time. It is also periodic.
There is a button for "continuous play" and if you click on that button, because of the periodicity
this animation it will play smoothly over and over again.
plots[animate]( [(1+.5*sin(t)*cos(5*s))*cos(s),
(1+.5*sin(t)*cos(5*s))*sin(s), s=0..2*Pi],
t=0..2*Pi, scaling=constrained,
numpoints=100,
color=blue, axes=none, frames=100 );
This last animation is not as complicated as it seems. It is "morphing" a circle. The parametric
equations in the animate command define a "circle" whose radius ( given by the term
1+sin(t)*.5*cos(5*s)) changes both with angle (the s variable) and with time (the t
variable which is also the frame parameter). Try changing any of the parameters in the
command. Even if you do not yet understand the equations, you can modify them to see what
happens. Small changes in the equations can lead to big changes in the animation.
18