Maple Guide
Maple Guide
By
Table of Contents
Introduction................................................................................................................... 4
Basic Commands & Concepts....................................................................................... 5
Exact verses Approximate Solutions............................................................................ 5
Obtaining Previous Results, The Ditto Operator .......................................................... 5
Expressions ................................................................................................................. 6
Setting a Variable to a Value ....................................................................................... 7
Setting a Variable Back to a Variable .......................................................................... 8
Defining a List and a Set ............................................................................................. 9
The seq Command..................................................................................................... 10
The evalf Command .................................................................................................. 12
The eval Command ................................................................................................... 13
The subs Command ................................................................................................... 15
Mathematical Functions ............................................................................................ 16
Trigonometric and Hyperbolic Functions............................................................... 16
Exponential and Logarithmic Functions................................................................. 17
Root Functions ...................................................................................................... 17
Other Functions..................................................................................................... 17
The solve Command.................................................................................................. 17
The fsolve Command ................................................................................................ 20
Functions ..................................................................................................................... 24
Defining a Function of a Single Variable ................................................................... 24
Using the map Command .......................................................................................... 24
Defining Piecewise Functions ................................................................................... 25
Defining a Function of Several Variables .................................................................. 27
Limits, Differentiation, Integration & Sums.............................................................. 29
Evaluating Limits of Function of a Single Variable ................................................... 29
Evaluating Limits of Multivariable Functions............................................................ 30
Derivatives of Functions of a Single Variable............................................................ 32
Partial Derivatives of Multivariable Functions........................................................... 35
Integration of Single Variable Functions ................................................................... 39
Integration of Multivariable Functions....................................................................... 40
Finite and Infinite Sums ............................................................................................ 43
The taylor Command................................................................................................. 46
Graphing ..................................................................................................................... 48
Two Dimensional Plots ............................................................................................. 48
The plot Command: Plotting Functions.................................................................. 48
The plot Command: Plotting Parametrically Defined Equations............................. 54
The implicitplot Command .................................................................................... 55
The contourplot Command .................................................................................... 57
Introduction
This manual is a quick reference guide to some of the Maple 8 and 9 commands
that are pertinent to Calculus I, II and III. It is designed to show you the syntax and
examples for specific Maple functions. It is not designed to show you how to put the
commands together to solve problems or to explain the ins and outs of Maple
programming. With this guide and your mathematical background you should be able to
use Maple to help solve more difficult problems and explore both the theory and
applications involved in the Calculus sequence.
The guide is organized by topic and is not to be read as a textbook. Many of the
examples that are given in the early sections use commands that are covered later in the
guide. While this may cause some mild frustration when you are first learning Maple,
once you have a little Maple under your belt you will find the extent of the examples
quite helpful.
Most of the material in this guide can also be found in Maple documentation and
the Maple Help System. In fact, both of these other resources offer a more complete
description of the command, its attributes and applicable options. One of the difficulties
with both the written and electronic help systems is that they are too complete. Most
descriptions in the help system explain the command to its fullest extent and offer rather
advanced examples. This guide concentrates on the way you will most likely use the
commands in a Calculus course and leaves the advanced topics alone. Curious readers
are certainly welcome to explore the help system for further explanations of the
commands given in this guide and many commands that we do not cover.
2
> %%;
3
> %%%;
5
Expressions
The syntax for mathematical expressions in Maple is quite similar to other programs like
Excel and to most graphing calculators. The main thing to watch is that you must always
use an * to denote multiplication. Otherwise, it is simply + for addition, for
subtraction, * for multiplication, / for division, ^ for powers and we always use
parentheses ( ) for grouping. Note that [ ] and { } have other uses in Maple. For
example,
> 3*x^2-2*x+7;
3 x2 2 x + 7
> 4^(x-2);
4
( 2 + x )
Maple will also give you an error if the expression you input is in some way ambiguous.
For example,
> x^x^x;
Error, `^` unexpected
> x^(x^x);
x
( xx )
> (x^x)^x;
( xx )
As you know parentheses can make a big difference in the meaning of an expression.
Note the difference in the following outputs.
> (x^2-7*x+2)/(x+3);
x2 7 x + 2
x+3
> x^2-7*x+2/x+3;
x2 7 x +
2
+3
x
x2 7 x +
2
x+3
> x^2-7*x+2/(x+3);
x := 2 h 7
Caution:
When you define a variable to be a particular value, every subsequence use of the
variable results in the value being substituted automatically. For example,
> f:=x->2*x^2+3*x-5;
f := x 2 x2 + 3 x 5
> x:=5;
x := 5
> 3*x;
15
> f(x);
60
> f(t);
2 t2 + 3 t 5
> x:=2*h-7;
x := 2 h 7
> f(x);
2 ( 2 h 7 )2 + 6 h 26
To reset a variable back to a variable, without any value, start with the variable followed
by the := followed by the variable in single quotes. For example,
> x:='x';
x := x
> f(x);
2 x2 + 3 x 5
Also, do not use this method to define a function, see the How To on defining functions.
For example, if we wanted to define to define the function f ( x ) = 2 x 2 + 3 x 5 the
command
> f:=2*x^2+3*x-5;
f := 2 x2 + 3 x 5
Would not do the trick. It does define f to be the given expression but it does not view f
as a function. Note the output of the following commands.
> f;
2 x2 + 3 x 5
> f(3);
2 x( 3 )2 + 3 x( 3 ) 5
The correct way to define this function is by,
> f:=x->2*x^2+3*x-5;
f := x 2 x2 + 3 x 5
> f(3);
22
5
> x:='x';
x := x
> x;
x
s := { 3, 4, x, y, w 2, t }
Notice that in a set duplicates are removed. We define a list in the same manner except
that we use square brackets instead of curly brackets. Notice here that duplicates are not
removed.
> t:=[1,2,3,4,4,4,5,6];
t := [ 1, 2, 3, 4, 4, 4, 5, 6 ]
> t;
[ 1, 2, 3, 4, 4, 4, 5, 6 ]
Another difference between lists and sets that you may have noticed above is that a set
may rearrange the order of the items whereas a list will not. For example,
> t:={1,2,5,8,3,4,4,4,5,6,2,2,7};
t := { 1, 2, 3, 4, 5, 6, 7, 8 }
> t;
{ 1, 2, 3, 4, 5, 6, 7, 8 }
> t:=[1,2,5,8,3,4,4,4,5,6,2,2,7];
t := [ 1, 2, 5, 8, 3, 4, 4, 4, 5, 6, 2, 2, 7 ]
> t;
[ 1, 2, 5, 8, 3, 4, 4, 4, 5, 6, 2, 2, 7 ]
10
number. For example, say that we wanted to create a sequence of numbers that
approached 1 from above. One way to do it would be as follows.
> seq(1+1/2^n,n=0..20);
3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537
2, , , , , , ,
,
,
,
,
,
,
,
,
,
,
2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536
131073 262145 524289 1048577
,
,
,
131072 262144 524288 1048576
We can evalf the list to produce decimal approximations to these values.
> evalf(seq(1+1/2^n,n=0..20));
2., 1.500000000, 1.250000000, 1.125000000, 1.062500000, 1.031250000, 1.015625000,
1.007812500, 1.003906250, 1.001953125, 1.000976562, 1.000488281, 1.000244141,
1.000122070, 1.000061035, 1.000030518, 1.000015259, 1.000007629, 1.000003815,
1.000001907, 1.000000954
To create a list we simply need to place the seq command inside square brackets.
> lst:=[evalf(seq(1+1/2^n,n=0..20))];
lst := [ 2., 1.500000000, 1.250000000, 1.125000000, 1.062500000, 1.031250000,
1.015625000, 1.007812500, 1.003906250, 1.001953125, 1.000976562, 1.000488281,
1.000244141, 1.000122070, 1.000061035, 1.000030518, 1.000015259, 1.000007629,
1.000003815, 1.000001907, 1.000000954 ]
To analyze the function we then define the function and use the map command on it and
the list.
> f:=x->(x^2-1)/(x-1);
f := x
x2 1
x1
> map(f,lst);
[ 3.000000000, 2.500000000, 2.250000000, 2.125000000, 2.062500000, 2.031249984,
2.015625024, 2.007812480, 2.003906304, 2.001953280, 2.000976896, 2.000487424,
2.000245760, 2.000122880, 2.000065536, 2.000032768, 2.000000000, 2.000000000,
2.000000000, 2.000000000, 2.000000000 ]
Although you will probably have little use for this we will do a simple animation. We
will display a graph of the function f ( x ) = sin (nx ) as n takes on integer values from 1 to
10. The plot command is what will create each image in the sequence, it would look
something like the following,
11
plot(sin(n*x),x=-2*Pi..2*Pi)
To create a sequence of these plots for different values of n, we simply place the plot
command inside the seq command.
seq(plot(sin(n*x),x=-2*Pi..2*Pi),n=1..10)
Finally, to make it an animation we use the display command on the seq command with
the display option of insequence set to true.
display(seq(plot(sin(n*x),x=-2*Pi..2*Pi),n=1..10),
insequence=true)
The display command is in the plots package which can be used once we load it in. All
in all the Maple commands would be,
> with(plots):
Warning, the name changecoords has been redefined
> display(seq(plot(sin(n*x),x=-2*Pi..2*Pi),n=1..10),
insequence=true);
When you click on the image you should see the animation toolbar at the top of the
window.
12
There is an optional value you can include to specify the number of decimal places the
approximation will use. This value either goes in square brackets after the evalf name or
as a parameter after the expression to be evaluated.
> evalf[100](Pi);
3.14159265358979323846264338327950288419716939937510582097494459230781\
6406286208998628034825342117068
> evalf(Pi,20);
3.1415926535897932385
Another way to force Maple to give you an approximate answer, or at least a decimal
answer is to at some point place a decimal number onto the expression. For example,
> f(4.7);
22.09
> f(47/100);
2209
10000
13
> subs(x=0,cos(x)/sin(x));
cos( 0 )
sin( 0 )
> eval(%);
Error, numeric exception: division by zero
One other use for the command is to investigate the levels of substitution in an expression
that is a composition of several expressions. For example, say we have the following
expressions.
> a:=2*x-1;
a := 2 x 1
> x:=3*y^2+2;
x := 3 y2 + 2
> y:=z^3+z^2+z+1;
y := z 3 + z 2 + z + 1
> a;
2
6 ( z3 + z2 + z + 1 ) + 3
The above command did all of the substitutions automatically and then output the result.
We will get the same output using the eval command.
> eval(a);
2
6 ( z3 + z2 + z + 1 ) + 3
If we include an evaluation level as the second parameter in the eval command it will do
only that many evaluations. For example,
> eval(a,1);
2x1
> eval(a,2);
6 y2 + 3
> eval(a,3);
2
6 ( z3 + z2 + z + 1 ) + 3
> eval(a,4);
2
6 ( z3 + z2 + z + 1 ) + 3
14
> eval(%);
Error, numeric exception: division by zero
Also, there are cases where the substitution does not go through the way we would want
it to. This usually happens when there is a simplification step done, usually without our
knowledge, before the substitution is done. In this case there is another substitution
command called algsubs that is a bit more powerful.
> subs(x+1=x-a,3*(x+1)^2+2*(x+1)-1);
3 ( x a )2 + 2 x + 1
> algsubs(x+1=x-a,3*(x+1)^2+2*(x+1)-1);
3 ( x a )2 1 + 2 x 2 a
The algsubs command will even go as far as to find the expression by factoring or doing
some other manipulation. For example,
> expand((x+1)^4);
15
x4 + 4 x3 + 6 x2 + 4 x + 1
> algsubs(x+1=y,x^4+4*x^3+6*x^2+4*x+1);
y4
> expand((x+1)^4+2*x+1);
x4 + 4 x3 + 6 x2 + 6 x + 2
> algsubs(x+1=y,x^4+4*x^3+6*x^2+6*x+2);
2 y 1 + y4
Mathematical Functions
The following is a list of some of the more useful mathematical functions and their Maple
syntax.
cos 1 ( x )
tan 1 ( x )
(x )
1
sec ( x )
csc 1 ( x )
sinh 1 ( x )
cosh 1 ( x )
tanh 1 ( x )
cot
Maple Syntax
sin(x)
cos(x)
tan(x)
cot(x)
sec(x)
csc(x)
sinh(x)
cosh(x)
tanh(x)
coth(x)
sech(x)
csch(x)
arcsin(x)
Notes
The sine function.
The cosine function.
The tangent function.
The cotangent function.
The secant function.
The cosecant function.
The hyperbolic sine function.
The hyperbolic cosine function.
The hyperbolic tangent function.
The hyperbolic cotangent function.
The hyperbolic secant function.
The hyperbolic cosecant function.
The inverse sine function.
arccos(x)
arctan(x)
arccot(x)
arcsec(x)
arccsc(x)
arcsinh(x)
arccosh(x)
arctanh(x)
coth 1 ( x )
(x )
csch 1 ( x )
sech
arccoth(x)
arcsech(x)
arccsch(x)
Maple Syntax
exp(x)
ln(x)
log10(x)
Notes
The exponential function.
The natural logarithm function.
The common logarithm function.
log[b](x)
Root Functions
Function
x
n
Maple Syntax
sqrt(x)
Notes
The square root function.
surd(x,n)
Other Functions
Function
x
Maple Syntax
abs(x)
Notes
The absolute value function.
17
or
> solve(x^4-5*x^2+6*x=2,x);
1, 1, 1 + 3 , 1 3
In the first solve command we let Maple determine that x was the variable. In the second
solve command we explicitly told Maple that our variable was x. To solve the system of
linear equations
2x + 3 y = 7
5x + 8 y = 9
we could use
> solve({2*x+3*y=7,5*x+8*y=9});
{ y = -17, x = 29 }
or
> solve({2*x+3*y=7,5*x+8*y=9},{x,y});
{ y = -17, x = 29 }
Note that the list of variables that are input in the solve command will make a difference
in the outputs. For example consider the following solve commands.
> solve(2*x+3*y+z=7);
{ z = 2 x 3 y + 7, x = x, y = y }
> solve(2*x+3*y+z=7,z);
2 x 3 y + 7
> solve({2*x+3*y+z-w=7,5*x+8*y-3*w+8*z=9},{x,y});
{ y = 17 11 z + w, x = 29 + 16 z w }
> solve({2*x+3*y+z-w=7,5*x+8*y-3*w+8*z=9},{x,y,z});
{ y = 17 11 z + w, x = 29 + 16 z w, z = z }
> solve({2*x+3*y+z-w=7,5*x+8*y-3*w+8*z=9},{x,y,z,w});
{ y = y, z = z, x = 12 y + 5 z, w = 17 + y + 11 z }
> solve({2*x+3*y+z-w=7,5*x+8*y-3*w+8*z=9});
{ y = y, z = z, x = 12 y + 5 z, w = 17 + y + 11 z }
> solve({2*x+3*y+z-w=7,5*x+8*y-3*w+8*z=9},x);
18
Since the solve command finds exact solutions the output can at times be very long. For
example.
> solve(x^3-7*x^2+2*x+3=0,x);
( 1916 + 12 I 9843 )
6
( 1/3 )
86
( 1/3 )
7 ( 1916 + 12 I 9843 )
+ ,
3
12
( 1/3 )
3 ( 1916 + 12 I 9843 )
43
7
+
( 1/3 )
3
3 ( 1916 + 12 I 9843 )
( 1916 + 12 I 9843 ) ( 1/3 )
1
86
,
+ I 3
( 1/3 )
2
6
3 ( 1916 + 12 I 9843 )
( 1916 + 12 I 9843 )
12
( 1/3 )
43
3 ( 1916 + 12 I 9843 )
( 1/3 )
7
3
1
86
I 3
( 1/3 )
6
2
3 ( 1916 + 12 I 9843 )
To obtain a numeric approximation to solutions of this form simply apply the evalf
command to the output.
> evalf(%);
6.630098729 0.1 10 -9 I, -0.5126801310 0.1732050808 10-8 I,
0.8825814030 + 0.1732050808 10 -8 I
As will frequently happen when you evalf something like this you will get some roundoff error. Note that all of the imaginary parts of the above solution are extremely small.
This is an indication that the solutions are in fact real. Also since the solve command
gives exact solutions there may be times when it can not give you a nice closed form.
When Maple can give you an exact solution it will usually give a RootOf statement.
Consider the following output.
> solve(x^4-5*x^2+6*x=3,x);
RootOf( _Z 4 5 _Z 2 + 6 _Z 3, index = 1 ), RootOf( _Z 4 5 _Z 2 + 6 _Z 3, index = 2 ),
RootOf( _Z 4 5 _Z 2 + 6 _Z 3, index = 3 ),
RootOf( _Z 4 5 _Z 2 + 6 _Z 3, index = 4 )
As you can see, Maple knows that the equation has four solutions but it cant find any of
them exactly. This is why it has essentially given you the question back in the solution.
As above, to obtain an approximate solution to the equation, apply the evalf command to
the above output.
19
> evalf(%);
1.538751996, 0.6068401503 + 0.5831600070 I, -2.752432296,
0.6068401503 0.5831600070 I
20
> fsolve(x^3-7*x^2+2*x+3=0);
-0.5126801315, 0.8825814030, 6.630098729
For equations that are not polynomials we expect a single solution as output from the
fsolve command, as below.
> fsolve(sin(x)=x-2);
2.554195953
> fsolve(sin(x)=x-2,x);
2.554195953
If we plot the curves we see that there is only one real solution to the equation and hence
no need to look for any more.
> with(plots):
Warning, the name changecoords has been redefined
> implicitplot({y=sin(x),y=x-2},x=-10..10,y=-10..10,
grid=[50,50]);
On the other hand, say we wanted to solve the equation sin ( x ) = 0 . This clearly has an
infinite number of solutions and although we know what they are lets see how the fsolve
command deals with an equation like this. Note that the simple application of the fsolve
command returns 0 as a solution.
> fsolve(sin(x)=0,x);
0.
If we were interested in finding a solution between 3 and 5 we would execute,
> fsolve(sin(x)=0,x=3..5);
3.141592654
21
Even if there is more than one solution in a given interval the fsolve command will return
only one. For example,
> fsolve(sin(x)=0,x=20..30);
25.13274123
> fsolve(sin(x)=0,x=27..30);
28.27433388
Lets look at a system of nonlinear equations. The following two commands are
identical, at least to Maple, and they have the same output.
> fsolve({4*x^2+sin(y)=2,y/2+cos(x)=1});
{ x = 0.6361393915, y = 0.3912093747 }
> fsolve({4*x^2+sin(y)=2,y/2+cos(x)=1},{x,y});
{ x = 0.6361393915, y = 0.3912093747 }
Note that we get an error if we try to solve for only one of the variables. The fsolve
command must find a numeric solution to all of the variables in the equations.
> fsolve({4*x^2+sin(y)=2,y/2+cos(x)=1},x);
Error, (in fsolve) y is in the equation, and is not solved for
If we graph the system of equations we see that there is another possible solution.
> implicitplot({4*x^2+sin(y)=2,y/2+cos(x)=1},x=-5..5,y=5..5,grid=[50,50]);
We can use the fsolve command to approximate this solution by restricting both x and y
to a rectangle that contains the other solution. For example,
> fsolve({4*x^2+sin(y)=2,y/2+cos(x)=1},{x=-5..0,y=-2..2});
{ x = -0.6361393915, y = 0.3912093747 }
22
There is one more thing to aware of when using the fsolve command. As you know from
linear algebra, if you have n variables and you want to find numeric solutions for all of
them then you will need at least n equations. The same is true for nonlinear equations.
Maple knows this and hence it does not even try to fsolve a system if there are fewer
equations than there are variables.
> fsolve({4*x^2*z+sin(y)=2,y+z/2+cos(x)=1});
Error, (in fsolve) number of equations, 2, does not match number of
variables, 3
23
Functions
Defining a Function of a Single Variable
To define a function of a single variable, start the command with the function name
followed by := followed by the independent variable followed by the arrow ->
followed by the mathematical expression for the function. For example, to define the
function f ( x ) = 2 x 2 + 3 x 5 we use the command,
> f:=x->2*x^2+3*x-5;
f := x 2 x2 + 3 x 5
Now you can use standard mathematical function notation to evaluate the function. For
example,
> f(0);
-5
> f(2);
9
> (f(x+h)-f(x))/h;
2 ( x + h ) 2 + 3 h 2 x2
h
24
1
0
x=0
otherwise
1
-1
0<x
otherwise
otherwise
4
25
x
x<1
3 x
x<2
otherwise
sin ( x ) + 2
> f:=x->piecewise( x<0, 1, x<1, x, x<2,3-x,sin(x)+2);
f := x piecewise( x < 0, 1, x < 1, x, x < 2, 3 x, sin ( x ) + 2 )
> plot(f(x),x=-2..5,y=0..3,discont=true);
x
x<1
3 x
x<2
otherwise
sin ( x ) + 2
> g:=x->piecewise(x>=-2 and x<=-1, 1, x<1, x, x<2, 3-x,
sin(x)+2);
g := x piecewise( -2 x and x -1, 1, x < 1, x, x < 2, 3 x, sin ( x ) + 2 )
> plot(g(x),x=-5..5,y=-3..3,discont=true);
26
Notice the vertical lines at 2 and 1 despite the fact that we used discont=true. This was
due to the use of and in the defining of one of the ranges. If we rearrange the piecewise
command a little we do get a better image of the function.
> g:=x->piecewise(x<-2, x, x<=-1, 1, x<1, x, x<2, 3-x,
sin(x)+2);
g := x piecewise( x < -2, x, x -1, 1, x < 1, x, x < 2, 3 x, sin ( x ) + 2 )
> plot(g(x),x=-5..5,y=-3..3,discont=true);
27
Now you can use standard mathematical function notation to evaluate the function. For
example,
> f(0,0);
-1
> f(2,7);
2117
Similarly, to define the function g ( x, y, z , w) = sin ( x ) + y ln ( z ) + w 2 we use,
> g:=(x,y,z,w)->sin(x)+y-ln(z)+w^2;
g := ( x, y, z, w ) sin ( x ) + y ln ( z ) + w2
> g(1,2,3,4);
sin ( 1 ) + 18 ln ( 3 )
28
x 2
> value(%);
3
> limit((x^2-1)/(x-1),x=1);
2
> limit(abs(x)/x,x=0);
undefined
> limit(abs(x)/x,x=0,left);
-1
> limit(abs(x)/x,x=0,right);
1
We can also take limits at infinity by placing infinity or infinity for the position.
> limit(arctan(t),t=infinity);
29
> limit(arctan(t),t=-infinity);
y2
+2w
z
> limit(g(x,y,z,w),{x=5,y=-2,z=3,w=sqrt(2)});
71
+2 2
3
Now for functions that are not as nice Maple could have a problem with these. In some
cases Maple will notice that the limit is path dependent and hence does not exist.
> f:=(x,y)->abs(x^2-y^2)/(x^2-y^2);
x2 y2
f := ( x, y ) 2 2
x y
> limit(f(x,y),{x=0,y=0});
30
undefined
> plot3d(f(x,y),x=-2..2,y=-2..2,axes=boxed);
In other cases Maple may not recognize the path dependence and simply return the
question.
> f:=(x,y)->(x+y)^2/(x^2+y^2);
f := ( x, y )
( x + y )2
y2 + x2
> limit(f(x,y),{x=0,y=0});
( x + y )2
limit 2 2 , { y = 0, x = 0 }
y + x
> plot3d(f(x,y),x=-2..2,y=-2..2,axes=boxed);
31
2x3
> Diff(f(x),x);
d 2
(x 3 x + 2)
dx
> value(%);
2x3
We can take higher order derivatives simply by adding more variables to the list of
arguments. For example,
> diff(f(x),x,x);
2
> diff(f(x),x,x,x);
0
> Diff(f(x),x,x);
d2 2
(x 3 x + 2)
d x2
> Diff(f(x),x,x,x);
d3 2
(x 3 x + 2)
d x3
> value(%);
32
0
We can also use the $ repeater to do higher order derivatives. The $ will repeat an
expression a given number of times. For example,
> x$2;
x, x
> x+7$2;
x + 7, x + 7
> george$7;
george, george, george, george, george, george, george
Using this in conjunction with the diff command allows us to short-cut some of the
notation for higher order derivatives. For example,
> diff(f(x),x$2);
2
> diff(sin(x),x$1023);
cos( x )
One minor difficulty with the Diff and diff commands is that they return the derivative as
an expression and not as a function. Frequently we wish to have the derivative of a
function defined as a function. If we use the Diff or diff command we must use the
unapply command to turn the expression into a function. The syntax of the unapply
command is
unapply(expr,var)
where expr is the expression to be converted to a function and var is the independent
variable. For example,
> f:=x->x^2-3*x+2;
f := x x 2 3 x + 2
> diff(f(x),x);
> df:=unapply(%,x);
> df(x);
2x3
df := x 2 x 3
2x3
> df(2);
33
1
The D command will also find the derivative of a function but its inputs and outputs are
quite different than those of Diff and diff. The D command takes as input a function
name only, just like the map command. It also outputs a function definition and not an
expression. For example,
> f:=x->x^2-3*x+2;
f := x x 2 3 x + 2
> D(f);
x2x3
Notice that the output suggests that what D is returning is a function that maps x to
2 x 3 . To create a function that represents the derivative of f we simply need to assign a
name to the output of the D command, the unapply command is not necessary. For
example,
> df:=D(f);
df := x 2 x 3
> df(2);
1
In fact we can also use the D command output as a function itself simply by appending an
(x) or evaluate it at a particular value.
> D(f)(x);
2x3
> D(f)(2);
1
Higher order derivatives can be accomplished with the D command if we append the
@@n operator, where n denotes the order of differentiation. For example the second and
third derivatives of f can be found using,
> (D@@2)(f);
2
> (D@@3)(f);
0
respectively. The implicitdiff command will find derivatives of implicitly defined
relations. The syntax of the implicitdiff command is as follows,
34
implicitdiff(expr,var1,var2)
where expr is the implicitly defined expression, var1 and var2 represent the derivative
d var 1
dy
. For example, to find
we use the command,
d var 2
dx
> implicitdiff(x^2-y^2+x*y=sin(x*y),y,x);
2 x + y cos( x y ) y
2 y x + cos( x y ) x
and to find
dx
we use the command,
dy
> implicitdiff(x^2-y^2+x*y=sin(x*y),x,y);
2 y x + cos( x y ) x
2 x y + cos( x y ) y
Similarly, we can give the implicit expression a name and use it in the implicitdiff
command. Note that the following definition is an assignment of an expression to t and
not a function definition.
> t:=x*y-2*y=x^3;
t := x y 2 y = x3
> implicitdiff(t,y,x);
y + 3 x2
x2
sin ( x + y ) + ( y x ) cos( x + y )
> diff(f(x,y),y);
35
sin ( x + y ) + ( y x ) cos( x + y )
> Diff(f(x,y),x);
> value(%);
> Diff(f(x,y),y);
> value(%);
( ( y x ) sin( x + y ) )
x
sin ( x + y ) + ( y x ) cos( x + y )
( ( y x ) sin( x + y ) )
y
sin ( x + y ) + ( y x ) cos( x + y )
Notice in the Diff command the notation has changed from the derivative to the partial
derivative. Maple automatically recognizes that the function is multivariate and hence
the derivatives will be partial derivatives. For higher order derivatives the order of partial
derivatives is read from left to right. For example,
> Diff(f(x,y),x,y);
2
( ( y x ) sin ( x + y ) )
y x
> value(%);
( y x ) sin ( x + y )
> Diff(f(x,y),y,x);
2
( ( y x ) sin ( x + y ) )
x y
> value(%);
> diff(f(x,y),y,x);
( y x ) sin ( x + y )
( y x ) sin ( x + y )
As with higher order derivatives of functions of a single variable we can use the $
notation to condense the command.
> diff(f(x,y),x$2,y$3,x$4);
3 sin ( x + y ) + ( y x ) cos( x + y )
> Diff(f(x,y),x$2,y$3,x$4);
9
( ( y x ) sin ( x + y ) )
x4 y3 x2
36
> diff(f(x,y),y$3,x$6);
3 sin ( x + y ) + ( y x ) cos( x + y )
The D command is a bit different for multivariate functions. As with single variable
functions it expects a function name only but if you look closely at the D command we
used for single variable functions there was no place where we told Maple what to take
the derivative with respect to. For single variable functions Maple noticed that there was
only one variable and assumed that that variable was the one you wanted. For
multivariate functions Maple can no longer make that assumption. To tell Maple which
variable to differentiate with respect to we place [i] between the D and the (f). The i
in the brackets is a number that represents the variable that is being differentiated with
respect to. The number corresponds to the position of the variable in the original
definition of the function. For example, to take the partial derivative of the function
> f:=(x,y)->(y-x)*sin(x+y);
f := ( x, y ) ( y x ) sin ( x + y )
with respect to x we use,
> D[1](f);
( x, y ) sin ( x + y ) + ( y x ) cos( x + y )
since x was the first variable in the list of independent variables when the function f was
defined. Likewise to take the partial derivative of f with respect to y we use,
> D[2](f);
( x, y ) sin ( x + y ) + ( y x ) cos( x + y )
since y was the second variable in the list of independent variables when the function f
was defined. Note that if we reverse the order of the variables in the definition, 1 will
correspond to y and 2 will correspond to x.
> f:=(y,x)->(y-x)*sin(x+y);
f := ( y, x ) ( y x ) sin ( y + x )
> D[1](f);
> D[2](f);
( y, x ) sin ( y + x ) + ( y x ) cos( y + x )
( y, x ) sin ( y + x ) + ( y x ) cos( y + x )
To do higher order derivatives we can replace [i] with a list of numbers. For example,
the second partial of f with respect to x would be found by
37
> f:=(x,y)->(y-x)*sin(x+y);
f := ( x, y ) ( y x ) sin ( x + y )
> D[1,1](f);
( x, y ) 2 cos( x + y ) ( y x ) sin ( x + y )
( x, y ) 2 cos( x + y ) ( y x ) sin ( x + y )
( x, y ) ( y x ) sin ( x + y )
> D[2,1](f);
( x, y ) ( y x ) sin ( x + y )
One thing to note is that the order of differentiation is read from right to left when using
the D command. That is, in our example,
> D[1,2](f);
( x, y ) ( y x ) sin ( x + y )
Maple took the partial with respect to y first and then it took the partial derivative of that
with respect to x. As with the Diff and diff commands we can use the $ option to shortcut the notation, For example,
> D[1$2](f);
( x, y ) 2 cos( x + y ) ( y x ) sin ( x + y )
> D[1$4,2$3,1$7](f);
( x, y ) 8 cos( x + y ) ( y x ) sin ( x + y )
The implicitdiff command for implicit differentiation is exactly the same for expressions
with more than two variables. For example,
> t:=x*y-2*z^2*y=x^3;
t := x y 2 z 2 y = x3
> implicitdiff(t,y,x);
y + 3 x2
x 2 z2
38
> implicitdiff(t,y,z);
4zy
x 2 z2
> implicitdiff(t,z,y);
x 2 z2
4zy
> Int(f(x),x);
x2 3 x + 2 dx
> value(%);
1 3 3 2
x x +2x
3
2
Definite integrals can be found just as easily, we simply replace the var in the above
syntax with a variable range. The range is, of course, the interval you are integrating
over. For example,
> f(x);
x2 3 x + 2
> int(f(x),x=1..3);
39
2
3
> Int(f(x),x=1..3);
3
x2 3 x + 2 dx
> value(%);
2
3
Maple also has some special commands for doing numeric approximations to integrals. It
has commands for Riemann sums, the trapezoidal rule and Simpsons rule. All of these
commands are in Maples student package. For an explanation of these commands please
see the section in this guide on the student package.
( y x ) sin ( x + y ) dx dy
> value(%);
sin ( x + y ) ( x + y ) + 2 x sin ( x + y )
> int(int(f(x,y),x),y);
sin ( x + y ) ( x + y ) + 2 x sin ( x + y )
> Int(Int(f(x,y),y),x);
( y x ) sin ( x + y ) dy dx
> value(%);
sin ( x + y ) ( x + y ) 2 sin ( x + y ) y
> int(int(f(x,y),y),x);
sin ( x + y ) ( x + y ) 2 sin ( x + y ) y
40
Definite integrals can also be found using the same syntax, just replace the variables with
variable ranges. For example,
> Int(Int(f(x,y),x=-2..3),y=0..1);
1
( y x ) sin ( x + y ) dx dy
0
-2
> value(%);
> int(int(f(x,y),x=-2..3),y=0..1);
2 sin ( 4 ) 3 sin ( 1 ) 3 sin ( 3 ) + 2 sin ( 2 )
Maple can also handle ranges that are dependent on other variables.
> Int(Int(f(x,y),x=-2..3*y-2),y=0..1);
1
3y 2
0
-2
( y x ) sin ( x + y ) dx dy
> value(%);
3 sin( 1 ) +
3
sin( 2 )
2
> int(int(f(x,y),x=-2..3*y-2),y=0..1);
3
3 sin( 1 ) + sin( 2 )
2
For triple integrals we simply add on another int.
> f:=(x,y,z)->x*sin(z)+cos(y);
f := ( x, y, z ) x sin ( z ) + cos( y )
> Int(Int(Int(f(x,y,z),z=-2..3),y=0..1),x=0..5);
5
x sin ( z ) + cos( y ) d z dy dx
0
0
-2
> value(%);
25
25
cos( 3 ) +
cos( 2 ) + 25 sin( 1 )
2
2
> int(int(int(f(x,y,z),z=-2..3),y=0..1),x=0..5);
25
25
cos( 3 ) +
cos( 2 ) + 25 sin( 1 )
2
2
> Int(Int(Int(f(x,y,z),z=2*x+3*y-4..3*x-y+7),y=x+1..3*x+2),x=0..5);
41
3x+ 2
3xy+7
x sin ( z ) + cos( y ) d z dy dx
0
1 x
2 x + 3 y 4
> value(%);
25
52
23
5
1
1
sin ( 5 ) + cos( 17 ) sin ( 17 ) cos( 57 ) +
sin ( 57 ) sin ( 26 )
2
3
9
33
363
16
5
19
5
2780
+ cos( 26 ) + 9 sin ( 4 ) 32 cos( 4 ) + sin ( 6 ) cos( 6 ) + cos( 2 ) +
sin ( 2 )
4
48
3
1089
26
+
sin( 1 ) + 7 cos( 1 )
3
> evalf(%);
11.70116137
> int(int(int(f(x,y,z),z=2*x+3*y-4..3*x-y+7),y=x+1..3*x+2),x=0..5);
25
52
23
5
1
1
sin ( 5 ) + cos( 17 ) sin ( 17 ) cos( 57 ) +
sin ( 57 ) sin ( 26 )
2
3
9
33
363
16
5
19
5
2780
+ cos( 26 ) + 9 sin ( 4 ) 32 cos( 4 ) + sin ( 6 ) cos( 6 ) + cos( 2 ) +
sin ( 2 )
4
48
3
1089
26
+
sin( 1 ) + 7 cos( 1 )
3
If you really want short-cut syntax for the double and triple integrals you can always
create a new command yourself. For example, we create four commands below that find
double and triple integrals, both have pretty-print versions and evaluation versions.
> dint:=(f,xrng,yrng)->int(int(f,xrng),yrng);
f d xrng dyrng
dint := ( f, xrng, yrng )
> Dint:=(f,xrng,yrng)->Int(Int(f,xrng),yrng);
f d xrng dyrng
Dint := ( f, xrng, yrng )
> tint:=(f,xrng,yrng,zrng)->int(int(int(f,xrng),yrng),zrng);
> Tint:=(f,xrng,yrng,zrng)->Int(Int(Int(f,xrng),yrng),zrng);
> Dint(f(x,y),x=-2..4,y=-3..8);
8
( y x ) sin ( x + y ) dx dy
-3
-2
> value(%);
> dint(f(x,y),x=-2..4,y=-3..8);
4 sin ( 12 ) + 10 sin ( 6 ) 7 sin ( 1 ) sin ( 5 )
> f:=(x,y,z)->x*sin(z)+cos(y);
f := ( x, y, z ) x sin ( z ) + cos( y )
> Tint(f(x,y,z),z=2*x+3*y-4..3*x-y+7,y=-x+1..3*x+2,x=0..5);
5
3x+ 2
3xy+7
x sin ( z ) + cos( y ) d z dy dx
0
1 x
2 x + 3 y 4
> value(%);
25
52
23
5
1
1
sin ( 5 ) + cos( 17 ) sin ( 17 ) cos( 57 ) +
sin ( 57 ) sin ( 26 )
2
3
9
33
363
16
5
19
5
2780
+ cos( 26 ) + 9 sin ( 4 ) 32 cos( 4 ) + sin ( 6 ) cos( 6 ) + cos( 2 ) +
sin ( 2 )
4
48
3
1089
26
+
sin( 1 ) + 7 cos( 1 )
3
> tint(f(x,y,z),z=2*x+3*y-4..3*x-y+7,y=-x+1..3*x+2,x=0..5);
25
52
23
5
1
1
sin ( 5 ) + cos( 17 ) sin ( 17 ) cos( 57 ) +
sin ( 57 ) sin ( 26 )
2
3
9
33
363
16
5
19
5
2780
+ cos( 26 ) + 9 sin ( 4 ) 32 cos( 4 ) + sin ( 6 ) cos( 6 ) + cos( 2 ) +
sin ( 2 )
4
48
3
1089
26
+
sin( 1 ) + 7 cos( 1 )
3
43
> Sum(i,i=1..5);
5
i=1
> value(%);
15
> Sum(i^3,i=1..50);
50
i3
i=1
> value(%);
1625625
> sum(i^3,i=1..50);
1625625
> sum(1/i,i=1..50);
13943237577224054960759
3099044504245996706400
> evalf(%);
4.499205338
> sum(1/i,i=1..500);
663338429989119806546143302387421466015138348898782940686870090780227\
937698636415400569017248053724834931036587121859174364111676672813\
949472763785044905480298961334427450045382592284705223585961537823\
8909694581687099
9765282975860379545848516602538973177301511766\
838567872846558671279507656107161785910367975985510264702441680886\
454516761775201775149778279241658755154640446941522074794053108833\
85229609852607806002629415184926954240
> evalf(%);
6.792823430
> sum(1/i-1/(i+1),i=1..1000000);
1000000
1000001
> evalf(%);
0.9999990000
For infinite sums simply set the ending bound to infinity. For example,
> sum(1/i-1/(i+1),i=1..infinity);
44
1
> sum(1/i^2,i=1..infinity);
2
6
> sum(1/i^3,i=1..infinity);
( 3 )
> sum(1/i^4,i=1..infinity);
4
90
Finite and infinite sums need not be entirely numeric. For example,
> Sum(1/i!*x^i,i=0..infinity);
i=0
xi
i!
> sum(1/i!*x^i,i=0..infinity);
ex
> sum(1/i*x^i,i=1..infinity);
ln ( 1 x )
Note that in the last couple expressions Maple noticed the form of the sum and simplified
the sum into a function. Similarly, we can define a function to be an infinite (or finite)
sum.
> f:=x->sum(1/i*x^i,i=1..infinity);
xi
f := x
i
i=1
> f(-3);
undefined
> f(-1);
ln ( 2 )
> f(1/2);
ln ( 2 )
45
1 2 1 3 1 4
x + x +
x + O( x 5 )
2
6
24
> taylor(sin(x),x=0,20);
1
1 5
1 7
1
1
1
x x3 +
x
x +
x9
x11 +
x13
6
120
5040
362880
39916800
6227020800
1
1
1
x15 +
x17
x 19 + O( x 20 )
1307674368000
355687428096000
121645100408832000
Note that in the expansion Maple attaches a O(n) last term that represents the tail of the
series. We can remove it by using the convert command. For example,
> taylor(sin(x),x=0,5);
x
1 3
x + O( x 5 )
6
> convert(taylor(sin(x),x=0,5),polynom);
1
x x3
6
With the convert command we can create a new command, called ntaylor, that will return
the nth degree Taylor polynomial of a function.
> ntaylor:=(f,val,n)->convert(taylor(f,val,n),polynom);
ntaylor := ( f, val, n ) convert( taylor( f, val, n ), polynom )
> ntaylor(sin(x),x=0,6);
x
1 3
1 5
x +
x
6
120
46
This command comes in handy when exhibiting the convergence of the Taylor
polynomial to the function, as we show below.
> plot([sin(x),seq(ntaylor(sin(x),x=0,n),n=1..20)],x=10..10,y=-5..5,numpoints=500);
47
Graphing
Maple has many advantages for teaching Calculus but one of its strongest is the plethora
of graphing commands and ease of creating animations. Although we will not discuss the
creation of animations here we will cover many of the graphing commands that are
applicable to Calculus I, II and III. After you create a Maple graph you can click on the
image to bring up the image toolbar. This toolbar will allow you to change several of the
image options simply by clicking a button. Another option you have is to right-click on
the image. This will bring up a pop-up menu of options as well as facilities to save the
image in a number of different file formats. As always, you can copy and paste Maple
graphs into any application that supports drag and drop graphics.
48
To graph more than one function on the same graph we simply place the set of functions
either in a list or a set. For example,
> plot([f(x),g(x),h(x)],x=-2*Pi..2*Pi);
> plot({f(x),g(x),h(x)},x=-2*Pi..2*Pi);
As with all sets and lists, the list retains its order and a set might not. Hence, if you use a
set here the colors of the different graphs may differ from the same command that uses a
list. When Maple graphs a function it does it so that the graph fits the box. This, in many
cases, will distort the image of the graph. To get a true picture of the function you can
include the scaling=constrained option. This will graph the function in a 1-1 manner.
You can get the same result by clicking the 1-1 button in the toolbar.
> plot(f(x),x=-2*Pi..2*Pi,scaling=constrained);
49
Another way to alter the vertical scale is by inputting a vertical scale. For example,
consider the difference between the following two graphs,
> plot(1/(x-1),x=0..2);
> plot(1/(x-1),x=0..2,y=-10..10);
This last image brings up another option that is frequently used with rational functions.
Note that in the above image the vertical asymptote is shown, to eliminate it we can add
the discont=true option.
> plot(1/(x-1),x=0..2,y=-10..10,discont=true);
The color option sets the color of the function. Possible values or the color option are:
aquamarine, black, blue, navy, coral, cyan, brown, gold, green, gray, grey, khaki,
50
magenta, maroon, orange, pink, plum, red, sienna, tan, turquoise, violet, wheat, white,
and yellow. For example,
> plot(f(x),x=-2*Pi..2*Pi,color=black);
When plotting more than one function you can use a list for the color option to control
each color independently.
> plot([f(x),g(x),h(x)],x=-2*Pi..2*Pi,
color=[red,black,blue]);
Another way to alter the lines appearance is with the linestyle option. The values for the
linestyle option are SOLID, DOT, DASH, and DASHDOT. Note that as of Maple 8
these options must be typed in uppercase
> plot(f(x),x=-2*Pi..2*Pi,color=black,linestyle=DASHDOT);
51
We can control the thickness of a line as well. Thicknesses can range from 1 to 15, a
thickness of 16 results in a thickness of 1, 17 to 2 and so on. For example,
> plot(f(x),x=-2*Pi..2*Pi,color=black,thickness=5);
In Calculus II you use the definite integral to, among other things, find the area between a
curve and the x-axis. To display this area you can add the filled=true option. For
example,
> plot(f(x),x=-2*Pi..2*Pi,filled=true);
In some cases the number of points Maple uses to graph a function is insufficient. To
compensate you can manually set the number of points used in a graph with the
numpoints option. For example,
52
> plot(sin(1/x),x=0..1);
> plot(sin(1/x),x=0..1,numpoints=10000);
Remember that the larger the number of points the longer it will take Maple to graph the
function. Another option that is used from time to time is the view option. The view
option will display only the portion of the graph you designate, no matter what domain
you gave the plot command. For example,
> plot(sin(x),x=-2*Pi..2*Pi,view=[0..5,0..1]);
The last option we will discuss for the plot command is the coords option. This option
allows you to change the coordinate system you are working with. The available values
for this option are: bipolar, cardioid, cassinian, elliptic, hyperbolic, invcassinian,
invelliptic, logarithmic, logcosh, maxwell, parabolic, polar, rose, and tangent. Most
53
likely, the only one you will use in a Calculus sequence is polar. When you include
coords=polar as an option the resulting graph will be graphed using the polar coordinate
system and not the rectangular system. For example,
> plot(sin(t),t=0..2*Pi,coords=polar);
y = cos(t )
for 0 t 2 , we use,
> plot([sin(t),cos(t),t=0..2*Pi]);
We can use any of the plot options as well as specify and x and y range for graphing. For
example,
54
> plot([sin(t),cos(t),t=0..2*Pi],x=-2..2,y=-2..2,
color=green,filled=true);
Most of the plot option also work with the implicitplot command, please see the plot
command information in this guide or the Maple documentation for a more detailed
explanation of the available options.
> implicitplot(x^2-y^2=3,x=-5..5,y=-5..5,color=black,
linestyle=DASHDOT);
55
One option that is not available is the numpoints option. When graphing an implicitly
defined relation, Maple uses a grid of points and not a list of points. So if you want to
increase the number of points used to graph the curve you need to add the grid option to
the implicitplot command. For example, look at the following image.
> implicitplot(x^2-y^2=0,x=-2..2,y=-2..2);
Notice that there is a square in the center. This square is an error produced by the fact
that the curve has a self-intersection at the origin. We can minimize the size of the
square, and sometimes remove it, by increasing the grid divisions as in the next
command.
> implicitplot(x^2-y^2=0,x=-2..2,y=-2..2,grid=[100,100]);
56
As with the numpoints option the larger the grid divisions the longer it will take to
produce an image.
> f:=(x,y)->sin(x*y);
f := ( x, y ) sin ( y x )
> contourplot(f(x,y),x=-Pi..Pi,y=-Pi..Pi,grid=[50,50]);
In addition to the implicitplot options the contourplot allows you to have some control
over the number and positions of the contours. For example, you can use the
contours=list option to set the contour positions to the values in a list.
> contourplot(f(x,y),x=-Pi..Pi,y=-Pi..Pi,grid=[50,50],
color=black,contours=[-1/2,1/4,1/2,3/4]);
57
You can also simply set the number of contours used by contours=n where n is the
number of contours that Maple should plot. Maple will then choose the positions for you.
> contourplot(f(x,y),x=-Pi..Pi,y=-Pi..Pi,grid=[50,50],
color=black,contours=5);
> gradplot(f(x,y),x=-Pi..Pi,y=-Pi..Pi);
58
Along with the other plot options the gradplot has an arrows option whose values are
LINE, THIN, SLIM and THICK. The default is THIN, LINE produces a plot without
arrowheads, SLIM and THICK are shown below.
> gradplot(f(x,y),x=-Pi..Pi,y=-Pi..Pi,arrows=SLIM);
> gradplot(f(x,y),x=-Pi..Pi,y=-Pi..Pi,arrows=THICK);
As is commonly done we can graph both the gradplot and contourplot together using the
display command.
> display(gradplot(f(x,y),x=-Pi..Pi,y=-Pi..Pi),
contourplot(f(x,y),x=-Pi..Pi,y=-Pi..Pi,grid=[50,50]));
59
Another, more common way, to paste the graphs together is to define a variable name to
each graph and then display the two variables. Note that we use the : to suppress the
output. The output from an assignment statement like the ones below is usually a very
long list of coordinates and basic drawing structures, nothing you want to see.
> a:=gradplot(f(x,y),x=-Pi..Pi,y=-Pi..Pi):
> b:=contourplot(f(x,y),x=-Pi..Pi,y=-Pi..Pi,grid=[50,50]):
> display(a,b);
> fieldplot([x,-y],x=-2..2,y=-2..2);
60
Infinity Plots
There are no special commands for infinity plots, in fact you simply use the plot
command. Infinity plots are a bit different so we gave them there own small section.
Whenever you place infinity as a bound for one of the ranges in a plot Maple will
automatically create an infinity plot where the endpoints of the axes are infinite. For
example,
> plot(sin(x), x=0..infinity);
> plot([exp(x),ln(x),x^2,sqrt(x),sin(x),(7*x^2-2)/(x^2+5)],
x=-infinity..infinity);
61
> logplot(exp(x),x=-3..10);
> loglogplot(x^7,x=1..10);
62
To alter the appearance of the vector use the shape option with either the arrow or
harpoon value. For example,
> arrow([1,2],shape=arrow);
63
> arrow([1,2],shape=harpoon);
To plot a vector that begins at one point and ends at another, input both points, as vectors,
and use the difference option, as below.
> arrow([1,2],[3,4],shape=arrow,difference,view=[-2..4,1..5]);
If you input two vectors without using the difference option Maple will graph the second
vector starting at the position of the first vector. For example,
> arrow([1,2],[3,4],shape=arrow,view=[-2..4,-1..7]);
64
If you place the two vectors in a single set then the vectors will be graphed together
starting at the origin.
> arrow({[1,2],[3,4]},shape=arrow,view=[-2..4,-1..5]);
Finally, if we input two sets of vectors Maple will graph the second set of vectors starting
at each of the position in the first set of vectors. For example,
> arrow({[0,0],[-3,-4],[1,2],[-1,1]},{[1,2],[3,4]},
shape=arrow);
65
66
> plot3d(x^2-y^2,x=-3..3,y=-3..3);
To plot several surfaces together you simply need to place the expressions in a set.
> plot3d({x^2-y^2,x^2+y^2-3},x=-3..3,y=-3..3);
Many of the following options can be invoked from the image toolbar but we will discuss
them briefly anyway. The axes option controls the style of axes used for the graph, as
you can see the default is none. The values for the axes option are: BOXED, NORMAL,
FRAME, and NONE. For example,
> plot3d({x^2-y^2,x^2+y^2-3},x=-3..3,y=-3..3,axes=boxed);
67
The filled option comes in handy when discussing integration. Just like the twodimensional case it fills in the volume between the xy-plane and the surface. For
example,
> plot3d(x^2-y^2,x=-3..3,y=-3..3,axes=boxed,filled=true);
To increase the number of points being used to plot the surface use the grid=[m,n] option.
The values of m and n will determine the number of slices used in the x and y directions
to plot the surface. Remember that the more divisions you use the longer it will take to
graph the surface. Compare the following two graphs.
> plot3d(ln(x/y),x=-5..5,y=-5..5,axes=boxed);
> plot3d(ln(x/y),x=-5..5,y=-5..5,axes=boxed,grid=[50,50]);
68
The labels option will label the axes, if shown. The labels must be strings, and one way
to insure that they are strings is to place them in double quotes.
> plot3d(ln(x/y),x=-5..5,y=-5..5,axes=boxed,grid=[50,50],
labels=[x,y,z]);
The projection option can take a value between 0 and 1. The smaller the projection
number the wider the angle of view. The closer the projection is to 1 the more orthogonal
the view becomes. For example,
> plot3d(x^2-y^2,x=-5..5,y=-5..5,axes=boxed,projection=0);
> plot3d(x^2-y^2,x=-5..5,y=-5..5,axes=boxed,projection=0.5);
> plot3d(x^2-y^2,x=-5..5,y=-5..5,axes=boxed,projection=1);
69
The style option specifies how the surface is to be drawn. The values are :POINT,
HIDDEN, PATCH, WIREFRAME, CONTOUR, PATCHNOGRID,
PATCHCONTOUR or LINE. The default style is PATCH. For example,
> plot3d(x^2-y^2,x=-5..5,y=-5..5,axes=boxed,style=HIDDEN);
The view option for the plot3d command allows you to set the viewing box to whatever
you desire. Another form of the option will simply scale the z-axis to the input bounds.
For example, if we simply give the view command a range Maple will restrict the z-axis
to be in this range.
> plot3d(x^2-y^2,x=-5..5,y=-5..5,axes=boxed,view=-5..5);
70
If, on the other hand, we give view a list of three ranges it will plot the surface inside the
rectangular solid defined by the ranges. For example,
> plot3d(x^2+y^2,x=-5..5,y=-5..5,axes=boxed,grid=[50,50],
view=[-1..2,-3..4,-5..5]);
The last option we will discuss is the coords option. The coords option allows you to
change the coordinate system you are working in. By default the coordinate system is
rectangular but you can choose from any of the following: bipolarcylindrical, bispherical,
cardioidal, cardioidcylindrical, casscylindrical, confocalellip, confocalparab, conical,
cylindrical, ellcylindrical, ellipsoidal, hypercylindrical, invcasscylindrical,
invellcylindrical, invoblspheroidal, invprospheroidal, logcoshcylindrical, logcylindrical,
maxwellcylindrical, oblatespheroidal, paraboloidal, paracylindrical, prolatespheroidal,
rosecylindrical, sixsphere, spherical, tangentcylindrical, tangentsphere, and toroidal. In
most cases you will only use cylindrical and spherical. In cylindrical coordinates Maple
expects the function to be of the form r = r ( , z ) . That is, the function must determine
the radius r in terms of theta and z. Also, the order of the ranges in the command is
important. The theta range must come before the z range. For example, the following
image is a correct view of the surface r = .
> plot3d(theta,theta=0..8*Pi,z=-1..1, coords=cylindrical,
grid=[200,10],axes=boxed);
whereas, the following surface is not. Note that in the following command we simply
switched the order of the ranges.
71
In spherical coordinates Maple assumes that the surface to be graphed is of the form
r = r ( , ) . That is, the function must determine the radius r in terms of theta and phi.
The order of the ranges in the command is important as well. The theta range must come
before the phi range. For example, the following image is a correct view of the surface
r = .
> plot3d(theta,theta=0..8*Pi,phi=0..Pi, coords=spherical,
grid=[200,10],axes=boxed);
When you are in spherical coordinates many times the surface is defined in the form of
r = r ( , ) . In cylindrical coordinates, on the other hand, there is another common form,
z = z (r , ) . We can graph surfaces of the form z = z (r , ) by adding a coordinate system
with the addcoords command. The command,
addcoords(z_cylindrical,[z,r,theta],[r*cos(theta),
r*sin(theta),z]);
will allow Maple to understand plots of z = z (r , ) surfaces as long as the ranges are in
the order of r and then theta.
72
plot3d(r*theta,r=0..10,theta=0..2*Pi,
coords=z_cylindrical,axes=BOXED);
There are many other options for the plot3d command and we encourage you to consult
the Maple documentation.
> cylinderplot(z+3*cos(2*theta),theta=0..Pi,z=0..3);
Note that the following plot3d command produces the same graph.
plot3d(z+3*cos(2*theta),theta=0..Pi,z=0..3,
coords=cylindrical);
73
> sphereplot(1,theta=0..2*Pi,phi=0..Pi/2,
scaling=constrained,axes=boxed);
Note that the following plot3d command produces the same graph.
plot3d(1,theta=0..2*Pi,phi=0..Pi/2,coords=spherical,
scaling=constrained,axes=boxed);
74
To alter the appearance of the vector use the shape option with either the arrow or
harpoon value. For example,
> arrow([1,2,3],shape=arrow,axes=boxed,color=black);
> arrow([1,2,3],shape=harpoon,axes=boxed,color=black);
To plot a vector that begins at one point and ends at another, input both points, as vectors,
and use the difference option, as below.
> arrow([1,2,3],[3,4,5],shape=arrow,difference,view=[-2..4,
-1..5,0..6],axes=boxed,color=black);
75
If you input two vectors without using the difference option Maple will graph the second
vector starting at the position of the first vector. For example,
> arrow([1,2,3],[3,4,5],shape=arrow,view=[-2..4,-1..7,0..8],
axes=boxed,color=black);
If you place the two vectors in a single set then the vectors will be graphed together
starting at the origin.
> arrow({[1,2,3],[3,4,5]},shape=arrow,view=[-2..4,-1..7,
0..8],axes=boxed,color=black);
Finally, if we input two sets of vectors Maple will graph the second set of vectors starting
at each of the position in the first set of vectors. For example,
76
> arrow({[1,2,3],[3,4,5]},{[1,1,1],[-2,-1,5],[3,-4,7],[5,9,2]},shape=arrow,axes=boxed,color=black);
> fieldplot3d([2*x,2*y,1],x=-1..1,y=-1..1,z=-1..1);
One nice option for the fieldplot3d command is the grid option. In 3d plots the grid
option controls the number of points used in constructing the graph. In many cases we
want to increase the number of points to give the image a finer resolution. In the case of
77
the field plot more vectors tends to complicate the image and fewer vectors tend to make
the graph clearer. By setting the grid option to low numbers can sometimes help in
analyzing the vector field.
> F:=(x,y,z)->[2*x,2*y,z^2];
F := ( x, y, z ) [ 2 x, 2 y, z 2 ]
> fieldplot3d(F(x,y,z),x=-1..1,y=-1..1,z=-1..2,axes=boxed,
grid=[5,5,5],color=black);
> gradplot3d(f(x,y,z),x=-2..2,y=-2..2,z=-2..2);
78
One nice option for the gradplot3d command is the grid option. In 3d plots the grid
option controls the number of points used in constructing the graph. In many cases we
want to increase the number of points to give the image a finer resolution. In the case of
the field plot more vectors tends to complicate the image and fewer vectors tend to make
the graph clearer. By setting the grid option to low numbers can sometimes help in
analyzing the gradient field. For example,
> gradplot3d(f(x,y,z),x=-2..2,y=-2..2,z=-2..2,grid=[5,5,5],
color=black,axes=boxed);
> implicitplot3d(x^2-y^2+z*x*y=2,x=-5..5,y=-5..5,z=-5..5);
79
> implicitplot3d(x^2-y^2+z*x*y=2,x=-5..5,y=-5..5,z=-5..5,
axes=boxed,grid=[20,20,20]);
> spacecurve([cos(t),sin(t),t/2],t=0..2*Pi);
80
As with most of the three dimensional graphics command you can use any of the options
that apply to the plot3d command, except for the surface style options. Also, since this is
a curve and not a surface you would use the numpoints option instead of the grid option
to refine the curve.
> spacecurve([cos(t),sin(t),t/2],t=0..10*Pi,color=black,
axes=boxed,numpoints=500);
81
If you read any of the Maple documentation you may notice that there is a display3d
command. The display3d command looks like it is for displaying three-dimensional
graphs but it actually just calls the display command. Hence you never need to use the
display3d command. There is one main restriction to the display command and that is
that it cannot plot a two-dimensional plot with a three-dimensional plot.
82
Packages
Maple is a very large and versatile mathematical software package. If we were to load all
of the Maple commands into memory when we started it up it would take up far too many
system resources. Instead, when we load Maple only a small number of commands are
loaded. Basically, there is enough to do simple calculations in a number of mathematical
areas including Calculus but more advanced commands are omitted. These more
advanced commands are in a number of code files called packages. To gain access to
these commands you can either reference the package the command is in or more simply
load the package into memory with the with command. Specifically, the command
with(pkg):
loads in the package named pkg. For example to load the plots package we use the
command
with(plots):
Note that we usually use the colon at the end of the with command. If we use the
semicolon we will get a listing of all of the functions in that package. The colon
suppresses this output. In this section we will discuss some of the Maple packages you
may encounter in Calculus I, II and III. There are many other packages that are specific
to certain areas of mathematics but we will not discuss them here.
83
cos( x ) sin ( x ) dx
then give the changevar command the substitution equation in the following form.
> changevar(cos(x)=u, %, u);
1
u du
0
To do the integral we simply hit the result with the value function.
> value(%);
2
3
The syntax is the same for the indefinite integral, except that we do a substitution at the
end. Take the integral,
> Int(sqrt(x^3-x^2+3*x-4)*(6*x^2-4*x+6), x);
x3 x 2 + 3 x 4 ( 6 x2 4 x + 6 ) dx
do the substitution,
> changevar(u=x^3-x^2+3*x-4, %, u);
2 u d u
4u
3
84
substitute back,
> subs(u=x^3-x^2+3*x-4,%);
4 ( x3 x2 + 3 x 4 )
3
( 3/2 )
x3 x2 + 3 x 4 ( 3 x2 2 x + 3 )
{ y = 5, x = 0 }
85
{ y = 0., x = 2.236067978 I }
> intercept(y = x^2-5,y=0);
{ y = 0, x = RootOf( 5 + _Z 2, label = _L3 ) }
> evalf(%);
{ y = 0., x = 2.236067977 }
{ x = 2.554195953, y = 0.5541959527 }
87
To evaluate the sums we use their corresponding sum commands. The sum commands
use the same syntax, except that the graphing options should be omitted. For example,
the Riemann sum values for each of the above images are below.
> leftsum(sin(x)+cos(x), x=0..2*Pi, 5);
2 4 2 i
2 i
sin
+ cos
5 i= 0 5
5
> value(%);
2
2
1 + 2 cos
2 cos
5
5
5
25 i = 0 25
25
> value(%);
0
> rightsum(sin(x)+cos(x), x=0..2*Pi, 5);
2 5 2 i
2 i
sin
+ cos
5 i= 1 5
5
> value(%);
2
2
1 + 2 cos
2 cos
5
5
5
> value(%);
0
> middlesum(sin(x)+cos(x), x=0..2*Pi, 5);
2 i + 1
2 i + 1
4
2
2
2
sin
+
cos
5 i= 0
5
5
> value(%);
2
1 + 2 cos 2 cos
5
5
5
88
1
i + 1
49 i +
2
1
2
sin
+ cos
25
25
25 i = 0
> value(%);
0
2 2 2 2
89
> value(%);
1
1
2
7
2
7
2
9
2
9
2
11
2
11
sin ( 1 ) + cos( 1 ) + sin + cos + sin + cos + sin + cos
5
5
5 5 5
5 5 5 5
5 5 5 5
5
2
13
2
13
1
1
+ sin + cos + sin ( 3 ) + cos( 3 )
5 5 5
5
5 5
> evalf(%);
0.8188482867
> trapezoid(sin(x)+cos(x), x=1..3, 50);
1
1
1 49
i
i 1
1
sin ( 1 ) + cos( 1 ) + sin 1 +
+ cos 1 +
+ sin ( 3 ) + cos( 3 )
50
50
25 i = 1
25
25 50
50
> evalf(value(%));
0.8298331624
Note that an error is generated if the number of divisions in Simpsons rule is not even.
> simpson(sin(x)+cos(x), x=1..3, 5);
Error, (in simpson) must have an even number of intervals
90
1
1
1
1
4 3
2 2i
2 2 i
sin ( 1 ) + cos( 1 ) + sin ( 3 ) + cos( 3 ) + sin +
+ cos +
9
9
9
9
9 i = 1 3 3
3 3
2 2
2i
2 i
+ sin 1 +
+ cos 1 +
9 i = 1
3
3
> value(%);
1
1
1
1
4
4
4
4
4
4
sin ( 1 ) + cos( 1 ) + sin ( 3 ) + cos( 3 ) + sin + cos + sin ( 2 ) + cos( 2 )
9
9
9
9
9 3 9
9
3 9
4
8
4
8
2
5
2
5
2
7
2
7
+ sin + cos + sin + cos + sin + cos
9 3 9
3 9 3 9
3 9 3 9
3
> evalf(%);
0.8300015109
> simpson(sin(x)+cos(x), x=1..3, 50);
1
1
1
1
sin ( 1 ) + cos( 1 ) + sin ( 3 ) + cos( 3 )
75
75
75
75
4
sin 24 +
75 i = 1 25
2 24
+ sin 1 +
75 i = 1
25
2i
24 2 i
+ cos +
25
25 25
2i
2 i
+ cos 1 +
25
25
> evalf(value(%));
0.8299438381
f( x( t ), y( t ) )
a
> f:=(x,y)->y*cos(x);
d y( t ) + d x( t ) dt
d t
d t
f := ( x, y ) y cos( x )
> Lineint(f(x,y),x=t,y=sin(t),t=1..2);
91
cos( t ) sin ( t )
d sin ( t ) + d t dt
d t
dt
> value(%);
( 3/2 )
( 3/2 )
1
1
( cos( 2 )2 + 1 )
+ ( cos( 1 )2 + 1 )
3
3
> evalf(%);
0.0659110793
92
93
where expr is the expression or function to be integrated, rng is the range of the
independent variable and opts is a list of options. The real power of this command is the
wealth of options it has. The basic command will find the approximation of the integral
using the midpoint Riemann sum with 10 rectangles. For example,
> with(Student[Calculus1]):
> ApproximateInt(x^2, x=0..1);
133
400
One of the options for the ApproximateInt command is the output option. Output can be
either value, sum, plot or animation. The default is value. Another well used option is
the partition option. The partition option can take on several forms but most often it is
used to set the number of divisions in the interval. For example,
> ApproximateInt(x^2, x=0..1,output=value);
133
400
> ApproximateInt(x^2, x=0..1,partition=100);
13333
40000
> ApproximateInt(x^2, x=0..1, output=sum,partition=10000);
2
1 9999 i
1
+
10000 i
10000 20000
=0
> evalf(value(%));
0.3333333325
Another option is the method option that allows you to set the approximation algorithm.
The method option can take any of the following values.
Value
bode
left
lower
midpoint
newtoncotes[N]
random
right
simpson
simpson[3/8]
trapezoid
upper
Rule
Bodes rule
Left Riemann Sum
Lower Riemann Sum
Midpoint Riemann Sum
Newton-Cotes' method of order N
Random selection of point in each interval
Right Riemann Sum
Simpson's rule
Simpson's 3/8 rule
Trapezoidal rule
Upper Riemann Sum
94
For example,
> ApproximateInt(x^2, x=0..1, output=sum,method=simpson);
2
2
1 9 i 2
i
1 i
1
100 + 4 10 + 20 + 10 + 10
60 i
=
0
> value(%);
1
3
Another of the possible outputs is the plot. With this option Maple will display a plot of
the approximation. For example,
> ApproximateInt(x^2, x=0..1, output=plot);
95
When there are a large number of rectangles being used the image can become cluttered.
To clean it up a bit you can use the outline option that will display just the outline of the
approximation. For example,
> ApproximateInt(sin(x), x=0..Pi, output=plot,method=upper,
partition=25,outline);
You can change the appearance of the boxes and the function by using the boxoptions
and functionoptions options. These two options take lists of options that apply to lines
and functions. For example,
96
The last output type is animation. This option will create a standard animation of the
approximation using more and more subdivisions. There are three options that control
the way the animation is done. The iterations option sets the number of successive
iterations of the method, that is, the number of frames in the animation. The refinement
option sets the way that the subintervals are divided. The two main values for this option
are halve and random. Halve will divide the interval in half and random will pick a
random point in the subinterval. The subpartition option determines the rectangle that
will be divided next. The values for this option are all, width and area. The value all
value indicates that every subinterval is subpartitioned, width indicates that the interval
with greatest width is subpartitioned and area indicates that the interval with greatest area
is subpartitioned. Note that some of these animations can take a long time to generate
especially if the number of iterations is high. For example, the command
> ApproximateInt(sin(x), 0..Pi, output=animation,
partition=2, refinement=halve, subpartition=all,
iterations=10);
produces the following sequence of images after the one pictured here. The first three
images are shown along with the final image.
97
> DerivativePlot(f(x),x=-5..5,derivativeoptions=[color=red],
functionoptions=[color=black],order=2);
98
> DerivativePlot(x^5-7*x^4,x=0..6,
functionoptions=[color=black],order=1..3);
There are several options for controlling the curve attributes, the most common are
functionoptions and inverseoptions. Each of these takes a list of options to be applied to
the function or the inverse. For example,
99
The MeanValueTheorem command has several options for customizing the display one
of which is the view option.
100
The MeanValueTheorem command can also output just the points of tangency with no
graph by adding the output=points option. For example,
> MeanValueTheorem(x^3 - x^2, x=0..2, output=points);
7
1
+
3
3
> MeanValueTheorem(sin(x), x=0..10,output=points);
By adding the numeric=true option we can convert the output to approximate solutions.
> MeanValueTheorem(sin(x), x=0..10,output=points,
numeric=true);
[ 1.625225308, 4.657959999, 7.908410616 ]
101
> NewtonsMethod(x^2+x+1,x=2,output=plot);
> NewtonsMethod(x^2+x+1,x=2,output=plot,iterations=100,
view=[-2..2,0..10]);
> NewtonsMethod(x^2+x-1,x=2,output=value);
0.6180339889
> NewtonsMethod(x^2+x-1,x=2,output=value,iterations=10);
0.6180339889
> NewtonsMethod(x^2+x-1,x=2,output=value,iterations=3);
0.6190476191
> NewtonsMethod(x^2+x-1,x=2,output=sequence,iterations=3);
2, 1.000000000, 0.6666666667, 0.6190476191
> NewtonsMethod(x^2+x-1,x=2,output=sequence,iterations=10);
2, 1.000000000, 0.6666666667, 0.6190476191, 0.6180344477, 0.6180339889
102
Note in the last command that there are not 10 values in the sequence. If Maple sees that
the successive values are the same it will remove them.
> SurfaceOfRevolution(cos(x)+1,x=0..Pi,output=integral);
2 ( cos( x ) + 1 ) sin ( x )2 + 1 dx
103
> SurfaceOfRevolution(cos(x)+1,x=0..Pi,output=value);
2
4 2 EllipticE
2
> evalf(%);
24.00301062
> SurfaceOfRevolution(cos(x)+1,x=0..Pi,output=plot,
axis=vertical);
> SurfaceOfRevolution(cos(x)+1,x=0..Pi,output=value,
axis=vertical);
2 x sin ( x )2 + 1 dx
0
> evalf(%);
37.70384091
> SurfaceOfRevolution(sin(1/x),x=1/2..2,output=plot,
axis=vertical);
> SurfaceOfRevolution(sin(1/x),x=1/2..2,output=plot);
104
> Tangent(sin(cos(x)),x=1,output=slope);
cos( cos( 1 ) ) sin ( 1 )
> evalf(%);
-0.7216061490
> Tangent(sin(cos(x)),x=1,output=line);
x cos( cos( 1 ) ) sin ( 1 ) + sin ( cos( 1 ) ) + cos( cos( 1 ) ) sin ( 1 )
> evalf(%);
0.7216061490 x + 1.236001408
105
> TaylorApproximation(sin(x),order=1..10,output=plot,view=[10..10,-3..3]);
106
> TaylorApproximation(sin(x),x=2,order=1..10,output=plot,
view=[-10..10,-3..3]);
to
107
cos( x )2 d x
4.934802202
> VolumeOfRevolution(x^2, x=0..4, output=plot,
axis=vertical);
2 x3 dx
> VolumeOfRevolution(sin(1/x),x=1/2..2,axis=vertical);
1
1
1
1
1
2 cos + 4 sin + Si cos( 2 ) sin( 2 ) Si ( 2 )
4
2
2
2 2
> evalf(%);
7.983763275
> VolumeOfRevolution(sin(1/x),x=1/2..2, output=plot);
109
x = , x = , x = 3
2
2
2
> Asymptotes(tan(x),x=0..20);
x = , x = 3 , x = 5 , x = 7 , x = 9 , x = 11
2
2
2
2
2
2
> Asymptotes(arctan(x),x);
y = , y =
2
2
110
> product((x-i),i=1..10);
( x 1 ) ( x 2 ) ( x 3 ) ( x 4 ) ( x 5 ) ( x 6 ) ( x 7 ) ( x 8 ) ( x 9 ) ( x 10 )
> Asymptotes(1/(product((x-i),i=1..10)),x);
[ y = 0, x = 1, x = 2, x = 3, x = 4, x = 5, x = 6, x = 7, x = 8, x = 9, x = 10 ]
3
, ,
2 2 2
111
0, , 3 , 5
2 2
, , 3
2 2 2
> InflectionPoints(3*x^4-16*x^3-66*x^2+360*x+5,x=0..5);
11
3
( 1/3 )
+ 3 ( 15294 + 6 315595 )
+ 2 ( 98 ( 15294 + 6 315595 )
( 196 ( 15294 + 6 315595 )
( 1/3 )
98 ( 15294 + 6 315595 )
( 1/3 )
( 1/3 )
( 2/3 )
( 1/4 )
+ 1818 )
+ 3 ( 15294 + 6 315595 )
+ 3 ( 15294 + 6 315595 )
112
( 2/3 )
( 2/3 )
( 3/4 )
+ 1818 )
+ 1818 3
+ 2
98 ( 15294 + 6 315595 )
( 15294 + 6 315595 )
1818
( 1/3 )
+ 3 ( 15294 + 6 315595 )
98 ( 15294 + 6 315595 )
( 1/3 )
15294 + 6 315595 )
( 98 ( 15294 + 6 315595 )
( 15294 + 6 315595 )
+ 1818
( 2/3 )
( 1/2 )
+ 572 2
( 2/3 )
( 1/3 )
+ 3 ( 15294 + 6 315595 )
( 2/3 )
+ 1818
( 1/6 )
6 ( 15294 + 6 315595 )
+ 3 ( 15294 + 6 315595 )
( 2/3 )
+ 3 ( 15294 + 6 315595 )
( 2/3 )
( 1/4 )
+ 1818 )
( 1/6 )
( 98 ( 15294 + 6 315595 )
( 1/3 )
2 ( 98 ( 15294 + 6 315595 )
( 1/3 )
, 8
( 1/4 )
+ 1818 )
+ 3 ( 15294 + 6 315595 )
( 2/3 )
( 3/4 )
+ 1818 )
( 1/3 )
98 ( 15294 + 6 315595 )
( 1/3 )
+ 3 ( 15294 + 6 315595 )
( 2/3 )
+ 1818 3
98 ( 15294 + 6 315595 )
( 1/3 )
+ 3 ( 15294 + 6 315595 )
( 2/3 )
+ 1818
( 15294 + 6 315595 )
1818
( 2/3 )
98 ( 15294 + 6 315595 )
( 1/3 )
( 1/2 )
+ 572 2
+ 2
15294 + 6 315595 )
( 98 ( 15294 + 6 315595 )
( 1/3 )
+ 3 ( 15294 + 6 315595 )
( 2/3 )
+ 1818
( 1/6 )
6 ( 15294 + 6 315595 )
+ 3 ( 15294 + 6 315595 )
( 2/3 )
( 1/4 )
+ 1818 )
> Roots(3*x^4-16*x^3-66*x^2+360*x+5,x,numeric);
[ -4.714892098, -0.01385382051 ]
> Roots(3*x^4-16*x^3-66*x^2+360*x+5,x=-1..1,numeric);
[ -0.01385382051 ]
> Roots(x^2+1,x);
[ ]
113
with(linalg):
The commands that are loaded are: BlockDiagonal, GramSchmidt, JordanBlock,
LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment,
backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, coldim,
colspace, colspan, companion, concat, cond, copyinto, crossprod, curl, definite, delcols,
delrows, det, diag, diverge, dotprod, eigenvals, eigenvalues, eigenvectors, eigenvects,
entermatrix, equal, exponential, extend, ffgausselim, fibonacci, forwardsub, frobenius,
gausselim, gaussjord, geneqns, genmatrix, grad, hadamard, hermite, hessian, hilbert,
htranspose, ihermite, indexfunc, innerprod, intbasis, inverse, ismith, issimilar, iszero,
jacobian, jordan, kernel, laplacian, leastsqrs, linsolve, matadd, matrix, minor, minpoly,
mulcol, mulrow, multiply, norm, normalize, nullspace, orthog, permanent, pivot,
potential, randmatrix, randvector, rank, ratform, row, rowdim, rowspace, rowspan, rref,
scalarmul, singularvals, smith, stackmatrix, submatrix, subvector, sumbasis, swapcol,
swaprow, sylvester, toeplitz, trace, transpose, vandermonde, vecpotent, vectdim, vector,
wronskian. Since this guide is primarily for the Calculus sequence we will look at a few
of the commands that pertain to Calculus. Although there are many commands here that
can be used in Calculus the two that we will discuss are dotprod and crossprod. These
find the dot product and cross product respectively. For example,
> dotprod([1,2,3],[5,6,7]);
38
> crossprod([1,2,3],[5,6,7]);
[ -4, 8, -4 ]
> dotprod([a,b,c],[d,e,f]);
ad+be+cf
> crossprod([a,b,c],[d,e,f]);
[ b f c e, c d a f, a e b d ]
114
with(VectorCalculus):
The commands that are loaded are: `&x`, `*`, `+`, `.`, `<,>`, `<|>`, AddCoordinates,
ArcLength, BasisFormat, Binormal, CrossProduct, Curl, Curvature, Del, DirectionalDiff,
Divergence, DotProduct, Flux, GetCoordinateParameters, GetCoordinates, Gradient,
Hessian, Jacobian, Laplacian, LineInt, MapToBasis, Nabla, PathInt, PrincipalNormal,
RadiusOfCurvature, ScalarPotential, SetCoordinateParameters, SetCoordinates,
SurfaceInt, TNBFrame, Tangent, TangentLine, TangentPlane, TangentVector, Torsion,
Vector, VectorField, VectorPotential, Wronskian, diff, evalVF, int, limit, series. We will
look at a few of these commands.
Defining a Vector
To define a vector, vector-valued function or vector field we place the coordinates inside
angled brackets, <>. For example,
> with(VectorCalculus):
Warning, the assigned names <,> and <|> now have a global binding
Warning, these protected names have been redefined and unprotected: *,
+, ., Vector, diff, int, limit, series
> a:=<1,2,3>;
a := e + 2 e + 3 e
x
y
z
> b:=<4,5,6>;
b := 4 e + 5 e + 6 e
x
y
z
> F:=t-><t,t^2,-3*t>;
F := t VectorCalculus:-`<,>`( t, t 2, VectorCalculus:-`*`( VectorCalculus:-`*`( 3, t ), -1 ) )
> F(3);
3e +9e 9e
x
y
z
> F(s-3);
( s 3 ) e + ( s 3 )2 e + ( 3 s + 9 ) e
x
y
z
> G:=(s,t)-><t-s,s+t^2,s^3-3*t>;
G := ( s, t ) VectorCalculus:-`<,>`( VectorCalculus:-`+`( t, VectorCalculus:-`*`( s, -1 ) ),
VectorCalculus:-`+`( s, t 2 ),
VectorCalculus:-`+`( s 3, VectorCalculus:-`*`( VectorCalculus:-`*`( 3, t ), -1 ) ) )
> G(2,4);
2 e + 18 e 4 e
x
y
z
116
> G(r,2);
( r + 2 ) e + ( r + 4 ) e + ( r 3 6 ) e
x
y
z
> a:=<1,2,3>;
> b:=<4,5,6>;
> a &x b;
a := e + 2 e + 3 e
x
y
z
b := 4 e + 5 e + 6 e
x
y
z
( -3 ) e + 6 e 3 e
x
y
z
> CrossProduct(a,b);
( -3 ) e + 6 e 3 e
x
y
z
117
> a:=<1,2,3>;
a := e + 2 e + 3 e
x
y
z
> b:=<4,5,6>;
b := 4 e + 5 e + 6 e
x
y
z
> a.b;
32
> DotProduct(a,b);
32
> F(t) . G(r,s);
t ( s r ) + t 2 ( r + s 2 ) 3 t ( r3 3 s )
> F:=t-><t,t^2,-3*t>;
F := t VectorCalculus:-`<,>`( t, t 2, VectorCalculus:-`*`( VectorCalculus:-`*`( 3, t ), -1 ) )
> ArcLength(F(t), t=0..2);
5
5
5
26 ln( 5 ) ln( 2 ) + ln( 4 10 + 26 10 )
2
2
2
> evalf(%);
7.741204804
> ArcLength(<cos(t),sin(t),t>, t=0..s);
2 2 sin ( s )2 arcsin( sin ( s ) )
cos( s )
> ArcLength(<cos(t),sin(t),t>, t=0..Pi);
118
> F:=t-><t,t^2,-3*t>;
F := t VectorCalculus:-`<,>`( t, t 2, VectorCalculus:-`*`( VectorCalculus:-`*`( 3, t ), -1 ) )
> Binormal(<cos(t),sin(t),t>, t);
1
1
1
1
sin ( t ) e cos( t ) e + sin ( t )2 + cos( t )2 e
2
2
x 2
y 2
z
> simplify(%);
1
1
1
sin ( t ) e cos( t ) e + e
2
x 2
y 2 z
> Binormal(F(t), t);
8 t2
2
+
3
( 3/2 )
2
( 10 + 4 t 2 )
10 + 4 t
24 t 2
e +
+
2
x
2
10 + 4 t
( 10 + 4 t 2 )
8 t2
2
( 3/2 )
10 + 4 t 2
8 t2
( 10 + 4 t 2 )
2
e z
2
10 + 4 t 2
( 10 + 4 t )
> simplify(%);
3
1
e +
e
2
5 + 2 t x 5 + 2 t2 z
119
> F:=VectorField(<y,-x,x+y>);
F := y e x e + ( x + y ) e
x
y
z
> Curl(F);
e e 2e
x
y
z
120
Warning, the assigned names <,> and <|> now have a global binding
Warning, these protected names have been redefined and unprotected: *,
+, ., Vector, diff, int, limit, series
> F:=t-><sin(t),cos(t),t>;
F := t VectorCalculus:-`<,>`( sin ( t ), cos( t ), t )
> Curvature(F(t),t);
1
4
2 sin( t ) 2 + 2 cos( t ) 2
> simplify(%);
1
2
> F:=t-><sin(t),cos(t),t^2>;
F := t VectorCalculus:-`<,>`( sin ( t ), cos( t ), t 2 )
> Curvature(F(t),t);
4 cos( t ) t
( 3/2 )
( 4 t2 + 1 )
sin ( t ) 4 sin ( t ) t
cos( t )
+
( 3/2 )
2
4 t + 1 ( 4 t2 + 1 )
4 t2 + 1
8t
+
+
( 4 t 2 + 1 )( 3/2 )
4 t2 + 1
( 1/2 )
4 t2 + 1
> simplify(%);
4 t2 + 5
( 4 t2 + 1 )
4 t2 + 1
> CF:=unapply(%,t);
4 t2 + 5
( 4 t2 + 1 )
CF := t
4 t2 + 1
> CF(2);
21
289
4913
17
> evalf(%);
0.06537869769
> CF(0);
5
121
> f:=(x,y)->x^2-y^2;
f := ( x, y ) VectorCalculus:-`+`( x2, VectorCalculus:-`*`( y2, -1 ) )
> Del(f(x,y));
> Gradient(f(x,y));
> Nabla(f(x,y));
2xe 2ye
x
y
2xe 2ye
x
y
2xe 2ye
x
y
> f:=(x,y,z,w)->(sin(x*w)-cos(y*z))/(sin(x*y)-cos(w*z));
f := ( x, y, z, w ) VectorCalculus:-`*`( VectorCalculus:-`+`(
sin ( VectorCalculus:-`*`( x, w ) ),
VectorCalculus:-`*`( cos( VectorCalculus:-`*`( y, z ) ), -1 ) ), 1/VectorCalculus:-`+`(
sin ( VectorCalculus:-`*`( x, y ) ),
VectorCalculus:-`*`( cos( VectorCalculus:-`*`( w, z ) ), -1 ) ) )
> f(x,y,z,w);
sin( x w ) cos( y z )
sin( x y ) cos( w z )
> Del(f(x,y,z,w));
122
cos( x w ) w
( sin ( x w ) cos( y z ) ) cos( x y ) y
e +
sin ( x y ) cos( w z )
( sin ( x y ) cos( w z ) )2
x
sin ( y z ) z
( sin ( x w ) cos( y z ) ) cos( x y ) x
e +
2
sin
(
x
y
)
cos
(
w
z
)
(
sin
(
x
y
)
cos
(
w
z
)
)
y
sin
(
y
z
)
y
(
sin
(
x
w
)
cos
(
y
z
)
)
sin
(
w
z
)
w
2
sin ( x y ) cos( w z )
z
( sin ( x y ) cos( w z ) )
> f:=(x,y)->sin(sqrt(x)+y^2);
f := ( x, y ) sin ( VectorCalculus:-`+`( x , y2 ) )
> diff(f(x,y),x);
1 cos( x + y2 )
2
x
> diff(f(x,y),y);
2 cos( x + y2 ) y
> diff(f(x,y),x,y);
sin ( x + y2 ) y
x
> diff(f(x,y),y,x);
sin ( x + y2 ) y
x
> f:=(x,y,z,w)->(sin(x*w)-cos(y*z))/(sin(x*y)-cos(w*z));
123
f := ( x, y, z, w ) VectorCalculus:-`*`( VectorCalculus:-`+`(
sin ( VectorCalculus:-`*`( x, w ) ),
VectorCalculus:-`*`( cos( VectorCalculus:-`*`( y, z ) ), -1 ) ), 1/VectorCalculus:-`+`(
sin ( VectorCalculus:-`*`( x, y ) ),
VectorCalculus:-`*`( cos( VectorCalculus:-`*`( w, z ) ), -1 ) ) )
> f(x,y,z,w);
sin( x w ) cos( y z )
sin( x y ) cos( w z )
> diff(f(x,y,z,w),z);
sin ( y z ) y
( sin ( x w ) cos( y z ) ) sin ( w z ) w
sin ( x y ) cos( w z )
( sin ( x y ) cos( w z ) )2
> diff(f(x,y,z,w),z,z,z);
sin ( y z ) y3
3 cos( y z ) y2 sin ( w z ) w 6 sin ( y z ) y sin ( w z )2 w2
+
sin ( x y ) cos( w z )
( sin ( x y ) cos( w z ) )2
( sin ( x y ) cos( w z ) )3
3 sin ( y z ) y cos( w z ) w2 6 ( sin ( x w ) cos( y z ) ) sin ( w z )3 w3
( sin ( x y ) cos( w z ) )2
( sin ( x y ) cos( w z ) )4
6 ( sin ( x w ) cos( y z ) ) sin ( w z ) w3 cos( w z ) ( sin ( x w ) cos( y z ) ) sin ( w z ) w3
+
+
( sin ( x y ) cos( w z ) )3
( sin ( x y ) cos( w z ) )2
> f:=(x,y)->sin(sqrt(x)+y^2);
f := ( x, y ) sin ( VectorCalculus:-`+`( x , y2 ) )
> DirectionalDiff(f(x,y),<1,1>,[x,y]);
124
1
1 cos( x + y2 )
+ 2 cos( x + y2 ) y
2
2
x
2
> DirectionalDiff(x^2-y^2,<1,1>,[x,y]);
2 (2 x 2 y)
2
> DirectionalDiff(x^2-y^2,<a,b>,[x,y]);
2xa2yb
a 2 + b2
> DirectionalDiff(sin(x^2-y^2)/z^2,<1,1,3>,[x,y,z]);
1
2 cos( x2 y 2 ) x 2 cos( x2 y2 ) y 6 sin ( x2 y 2 )
11
11
z2
z2
z3
> ddf:=unapply(%,x,y,z);
1
2 cos( x2 y 2 ) x 2 cos( x2 y2 ) y 6 sin ( x2 y 2 )
11
ddf := ( x, y, z )
11
z2
z2
z3
> ddf(3,5,9);
1
4
2
11 cos( 16 ) +
sin( 16 )
11
81
243
> evalf(%);
0.01354456847
125
> F:=VectorField(<x^2,y^2,z^2>);
F := x2 e + y2 e + z 2 e
x
y
z
> Divergence(F);
2x+2y+2z
> F:=VectorField(<y,-x,x+y>);
F := y e x e + ( x + y ) e
x
y
z
> Divergence(F);
0
> F:=VectorField(<sin(x),cos(y),tan(z)>);
F := sin ( x ) e + cos( y ) e + tan( z ) e
x
y
z
> Divergence(F);
cos( x ) sin ( y ) + 1 + tan( z )2
126
where v is the vector formula for the surface and paramrngs are the ranges of the
parameters that trace out the surface. For example,
> with(VectorCalculus):
Warning, the assigned names <,> and <|> now have a global binding
Warning, these protected names have been redefined and unprotected: *,
+, ., Vector, diff, int, limit, series
> Flux(F,Sphere(<3,5,9>,1));
4
3
4
3
> Flux(F,Box(-1..1,1..2,3..7));
8
> Flux(F,Box(-1..1,1..2,3..7,inward));
-8
127
> Flux(F,Box(-1..1,1..2,3..7,outward));
8
e +4e +9e
x
y
z
> F:=VectorField(<cos(x),sin(y),z>);
F := cos( x ) e + sin ( y ) e + z e
x
y
z
> evalVF(F,<Pi,Pi/2,3>);
e +e +3e
x
y
z
where expr is the expression to be integrated and region id the region we are integrating
over. The region argument if of the form
[x,y] = RegionType
or
[x,y,z] = RegionType
where the RegionType is any of the following: Circle, Ellipse, Parallelepiped, Rectangle,
Region, Sector, Sphere, Tetrahedron or Triangle. The Circle has syntax,
Circle(center,radius)
where center is the center of the sphere given as a vector and radius is the radius of the
sphere. Note that the center must be a two-dimensional vector. The Ellipse has syntax,
Ellipse(eqn)
where eqn is the equation of the ellipse, in the form of eqn = 0. The Parallelepiped has
syntax,
Parallelepiped(rng1,rng2,rng3,)
where rng1, rng2, are all ranges. Note that the number of ranges must match the
number of variables and that the ranges may not depend on the variables of integration.
The Rectangle has syntax,
Rectangle(rng1,rng2)
where rng1 and rng2 are ranges. The Region has syntax,
Region (rng1,rng2,rng3,)
where rng1, rng2, are all ranges. Note that the number of ranges must match the
number of variables and that the ith range may only depend on the first i1 variables. The
Sector has syntax,
Sector(obj,start,finish)
where obj is either a circle or ellipse. The start is the angle measure (in radians) of the
beginning point of the sector and finish is the angle measure (in radians) of the ending
point of the sector. The Sphere has syntax,
Sphere(center,radius)
129
where center is the center of the sphere given as a vector and radius is the radius of the
sphere. The Tetrahedron has syntax,
Tetrahedron(v1,v2,v3,v4)
where v1, v2, v3 and v4 are three-dimensional vectors representing the vertices. The
Triangle has syntax,
Triangle(v1,v2,v3)
where v1, v2 and v3 are two-dimensional vectors representing the vertices. For example,
> with(VectorCalculus):
Warning, the assigned names <,> and <|> now have a global binding
Warning, these protected names have been redefined and unprotected: *,
+, ., Vector, diff, int, limit, series
130
9 2
32
> int(F,y=-Pi..Pi);
sin ( y ) e + z e
y
z
2 cos( x ) e + 2 z e
x
z
> int(F,z=0..1);
1
cos( x ) e + sin ( y ) e + e
y 2 z
x
> int(int(int(F,x=0..Pi),y=-Pi..0),z=0..2);
4 e + 2 2 e
y
z
131
Jacobian(expr,vars,det)
where expr is the list or vector of vectors, vars is a list of variables and an optional
argument det which is input as 'determinant' and will force the evaluation of the
determinant. If the det argument is not present the command will return just the Jacobian
matrix. For example,
> with(VectorCalculus):
Warning, the assigned names <,> and <|> now have a global binding
Warning, these protected names have been redefined and unprotected: *,
+, ., Vector, diff, int, limit, series
> Jacobian([r*cos(t),r*sin(t)],[r,t]);
cos( t ) r sin( t )
sin( t ) r cos( t )
> Jacobian([r*cos(t),r*sin(t)],[r,t],'determinant');
cos( t ) r sin( t ), cos( t ) 2 r + r sin( t ) 2
sin( t ) r cos( t )
> (J,d):=Jacobian([r*cos(t),r*sin(t)],[r,t],'determinant');
cos( t ) r sin( t )
J, d :=
, cos( t ) 2 r + r sin( t ) 2
sin( t ) r cos( t )
> d;
cos( t )2 r + r sin ( t )2
> simplify(d);
r
> Jacobian(<r*cos(t),r*sin(t)>,[r,t],'determinant');
cos( t ) r sin( t ), cos( t ) 2 r + r sin( t ) 2
sin( t ) r cos( t )
> (J,d):=Jacobian(<r*sin(phi)*cos(theta),
r*sin(phi)*sin(theta),r*cos(phi)>,[r,phi,theta],
'determinant');
sin ( ) cos( ) r cos( ) cos( ) r sin ( ) sin ( )
J, d := sin ( ) sin ( ) r cos( ) sin ( ) r sin ( ) cos( ) , sin ( )3 cos( )2 r 2
cos( )
r sin ( )
0
+ sin ( )3 sin ( )2 r 2 + r 2 cos( )2 cos( )2 sin ( ) + r 2 cos( )2 sin ( )2 sin ( )
> d;
sin ( )3 cos( )2 r 2 + sin ( )3 sin ( )2 r 2 + r 2 cos( )2 cos( )2 sin ( )
+ r 2 cos( )2 sin ( )2 sin ( )
> simplify(d);
132
sin ( ) r 2
> (J,d):=Jacobian(<u+v,u-v>,[u,v],'determinant');
1 1
J, d :=
, -2
1 -1
e +e
2 x
z
133
where center is the center of the sphere given as a vector and radius is the radius of the
sphere. Note that the center must be a two-dimensional vector. The Ellipse has syntax,
Ellipse(eqn)
where eqn is the equation of the ellipse, in the form of eqn = 0. The Line has syntax,
Line(pt1,pt2)
where pt1 and pt2 are two points that represent the directed line segment from pt1 to pt2.
The LineSegments has syntax,
LineSegments(pt1,pt2,pt3,pt4,)
where pt1, pt2, pt3, pt4, are all points. The only points that are required are pt1 and
pt2. The path of integration will be the directed line segment from pt1 to pt2 followed by
the directed line segment from pt2 to pt3, then pt3 to pt4 and so on. The Path has syntax,
Path(expr,rng)
where expr is the vector-valued function that represents a general path and rng is the
range of the parameter. For example,
> with(VectorCalculus):
Warning, the assigned names <,> and <|> now have a global binding
Warning, these protected names have been redefined and unprotected: *,
+, ., Vector, diff, int, limit, series
> SetCoordinates(cartesian[x,y]);
cartesianx, y
> F:=VectorField(<x^2,y>);
F := x2 e + y e
x
y
> LineInt(F,Line(<1,2>,<3,-4>));
44
3
> LineInt(F,LineSegments(<0,0>,<1,1>,<1,-1>));
5
6
> F:=VectorField(<x^2,y^2>);
F := x2 e + y2 e
x
y
> LineInt(F,Path(<t,t^4>,t=0..5));
134
81380250
> F:=VectorField(<-y,x>);
F := y e + x e
x
y
> LineInt(F,Circle(<0,0>,r));
2 r2
> LineInt(F,Ellipse(x^2/4+y^2/9-1));
12
> LineInt(F,Arc(Circle(<0,0>,r),0,Pi));
r2
> LineInt(F,Arc(Ellipse(x^2/4+y^2/9-1),0,Pi/2));
3
135
where pt1 and pt2 are two points that represent the directed line segment from pt1 to pt2.
The LineSegments has syntax,
LineSegments(pt1,pt2,pt3,pt4,)
where pt1, pt2, pt3, pt4, are all points. The only points that are required are pt1 and
pt2. The path of integration will be the directed line segment from pt1 to pt2 followed by
the directed line segment from pt2 to pt3, then pt3 to pt4 and so on. The Path has syntax,
Path(expr,rng)
where expr is the vector-valued function that represents a general path and rng is the
range of the parameter. For example,
> with(VectorCalculus):
Warning, the assigned names <,> and <|> now have a global binding
Warning, these protected names have been redefined and unprotected: *,
+, ., Vector, diff, int, limit, series
> SetCoordinates(cartesian[x,y]);
cartesianx, y
> f:=(x,y)->x^2+y;
f := ( x, y ) VectorCalculus:-`+`( x 2, y )
> PathInt(f(x,y),[x,y]=Line(<1,2>,<3,-4>));
20 10
3
> PathInt(f(x,y),[x,y]=LineSegments(<0,0>,<1,1>,<1,-1>));
5 2
+2
6
> PathInt(f(x,y),[x,y]=Path(<t,t^2>,t=0..2));
33 17
1
+
ln( 4 + 17 )
8
32
> PathInt(f(x,y),[x,y]=Circle(<0,0>,2));
8
> PathInt(f(x,y),[x,y]=Ellipse(x^2+y^2/3-1));
2
6 10
6
3 EllipticK
+
3 EllipticE
3
3 3
3
1
1
1
2 3 ln ( 2 ) +
3 ln ( 5 2 4 3 )
2
4
8
1
1
1
2
3 ln( 2 )
3 ln( 5 2 4 3 )
2
8
4
136
> evalf(%);
4.938620310
> PathInt(f(x,y),[x,y]=Arc(Circle(<0,0>,1),0,Pi/2));
+1
4
> PathInt(x,[x,y]=Arc(Ellipse(x^2+y^2/2-1),0,Pi/2));
1
+
2 4
> PrincipalNormal(<cos(t),sin(t)>,t);
cos( t ) e sin( t ) e
x
y
> PrincipalNormal(<cos(t),sin(t)>);
cos( t ) e sin( t ) e
x
y
> PrincipalNormal(<cos(t),sin(t),t>,t);
1
1
2 cos( t ) e
2 sin ( t ) e
2
x 2
y
> PrincipalNormal(<cos(t),sin(t),t>);
1
1
2 cos( t ) e
2 sin ( t ) e
2
x 2
y
> PrincipalNormal(<t,t^2,t^3>);
137
8 t + 36 t 3
t ( 8 t + 36 t 3 )
+
e
+
( 3/2 )
( 3/2 )
2
4
x
2
4
2 (1 + 4 t + 9 t )
(1 + 4 t + 9 t )
3 t 2 ( 8 t + 36 t 3 )
6t
+
e
( 3/2 )
2
4
2
4
z
1
+
4
t
+
9
t
2 (1 + 4 t + 9 t )
e +
1+4t +9t y
> simplify(%);
2 t ( 2 + 9 t2 )
2 ( 9 t4 1 )
6 t ( 2 t2 + 1 )
e
+
e
( 3/2 )
( 3/2 )
( 3/2 )
2
4
2
4
2
4
x
y
z
(1 + 4 t + 9 t )
(1 + 4 t + 9 t )
(1 + 4 t + 9 t )
> RadiusOfCurvature(<cos(t),sin(t)>,t);
1
> RadiusOfCurvature(<cos(t),sin(t),t>,t);
2
> RadiusOfCurvature(<cos(t),sin(t),t>);
2
> RadiusOfCurvature(<t,t^2,t^3>);
1 + 4 t2 + 9 t4
2
9 t4 + 9 t2 + 1
( 1 + 4 t2 + 9 t4 )
> RadiusOfCurvature(<t,2*t,3*t>);
138
> SetCoordinates(cartesian[x,y,z]);
cartesianx, y, z
> F:=VectorField(<x,y^2,z^3>);
F := x e + y2 e + z 3 e
x
y
z
> ScalarPotential(F);
x2 y3 z 4
+
+
2
3
4
> F:=VectorField(<6*x*sin(y)+z^x*ln(z),3*x^2*cos(y),
z^x*x/z>);
zx x
e
F := ( 6 x sin ( y ) + z x ln ( z ) ) e + 3 x2 cos( y ) e +
z z
x
y
> ScalarPotential(F);
3 x 2 sin ( y ) + z x
> Del(3*x^2*sin(y)+z^x);
zx x
( 6 x sin ( y ) + z x ln ( z ) ) e + 3 x2 cos( y ) e +
e
z z
x
y
> F:=VectorField(<x^2*sin(y),z*cos(x),z^2>);
F := x2 sin ( y ) e + z cos( x ) e + z 2 e
x
y
z
> ScalarPotential(F);
139
> SurfaceInt(x^2+y^2+z^2,[x,y,z]=Surface(<s,t,2*s-t>,
[s,t]=Triangle(<0,0>,<2,0>,<0,1>)));
3 6
> SurfaceInt(y^2,[x,y,z]=Sphere(<0,0,0>,3));
108
> SurfaceInt(x*y*z,[x,y,z]=Box(1..2,3..4,5..6));
693
4
TNBFrame(expr,var,out)
where expr is the curve, var is the parameter for the curve. The out argument is optional
and has the form output=[T] where T can be replaced by B or N or a list of these. The
out specifies the desired vectors in the output. If the out is absent the output will be all
three vectors. For example,
> with(VectorCalculus):
Warning, the assigned names <,> and <|> now have a global binding
Warning, these protected names have been redefined and unprotected: *,
+, ., Vector, diff, int, limit, series
> TNBFrame(<sin(t),cos(t),t>,t);
1
1
2
2 cos( t ) e
2 sin ( t ) e +
e , sin ( t ) e cos( t ) e ,
2
2 z
x 2
y
x
y
1
1
1
1
2 cos( t ) e
2 sin ( t ) e + 2 cos( t )2
2 sin ( t )2 e
2
2
x 2
y 2
z
> TNBFrame(<sin(t),cos(t),t>,t,'output'=['T']);
1
1
2
2 cos( t ) e
2 sin ( t ) e +
e
2
2 z
x 2
y
> TNBFrame(<sin(t),cos(t),t>,t,'output'=['N']);
sin( t ) e cos( t ) e
x
y
> TNBFrame(<sin(t),cos(t),t>,t,'output'=['B']);
1
1
1
1
2 cos( t ) e
2 sin ( t ) e + 2 cos( t )2
2 sin ( t )2 e
2
2
x 2
y 2
z
> TNBFrame(<sin(t),cos(t),t>,t,'output'=['T','B']);
1
1
2
2 cos( t ) e
2 sin ( t ) e +
e ,
2
2 z
x 2
y
1
1
1
1
2 cos( t ) e
2 sin ( t ) e + 2 cos( t )2
2 sin ( t )2 e
2
2
2
2
x
y
z
> sqrt(add((TNBFrame(<sin(t),cos(t),t>,t,
'output'=['T'])[i])^2,i=1..3));
1
2 + 2 sin( t ) 2 + 2 cos( t )2
2
> simplify(%);
1
> simplify(sqrt(add((TNBFrame(<sin(t),cos(t),t>,t,
'output'=['N'])[i])^2,i=1..3)));
141
1
> simplify(sqrt(add((TNBFrame(<sin(t),cos(t),t>,t,
'output'=['B'])[i])^2,i=1..3)));
1
> TangentLine(<t,t^3,sqrt(t)>,t=3);
t 3
e
( 3 + t ) e + ( 27 + 27 t ) e + 3 +
6 z
x
y
> TangentLine(<sin(t),cos(t),sin(cos(t))>,t=Pi/2);
e te te
x
y
z
> TangentLine(<sin(t),cos(t),sin(cos(t))>,t=a);
( sin ( a ) + t cos( a ) ) e + ( cos( a ) t sin ( a ) ) e +
x
y
( sin ( cos( a ) ) t cos( cos( a ) ) sin ( a ) ) e
z
142
> with(VectorCalculus):
Warning, the assigned names <,> and <|> now have a global binding
Warning, these protected names have been redefined and unprotected: *,
+, ., Vector, diff, int, limit, series
> TangentPlane(<s,t,s^2+t^2>,s=a,t=b);
( a + s ) e + ( b + t ) e + ( a 2 + b2 + 2 s a + 2 t b ) e
x
y
z
> TangentPlane(<s,t,s^2-t^2>,s=0,t=0);
se +te
x
y
> TangentPlane(<s,t,s^2-t^2>,s=1,t=1);
(1 + s) e + (1 + t) e + (2 s 2 t) e
x
y
z
> TangentPlane(<s^2,t^3,s+t>,s=a,t=b);
( a 2 + 2 s a ) e + ( b3 + 3 t b2 ) e + ( a + b + s + t ) e
x
y
z
> TangentVector(<t,t^2,t^3>,t);
e + 2 t e + 3 t2 e
x
y
z
> TangentVector(<sin(t),cos(t),t>,t);
cos( t ) e sin( t ) e + e
x
y
z
> TangentVector(<t^2,t^3>,t);
143
2 t e + 3 t2 e
x
y
> TangentVector(<t,t^2,t^3>);
e + 2 t e + 3 t2 e
x
y
z
> TangentVector(<sin(t),cos(t),t>);
cos( t ) e sin( t ) e + e
x
y
z
> TangentVector(<t^2,t^3>);
2 t e + 3 t2 e
x
y
> TangentVector(<a*t^2,b*t^3>);
Error, (in VectorCalculus:-TangentVector) could not determine unique
indeterminate: {a, b, t}
> Torsion(<sin(t),cos(t),t>,t);
1
2 sin( t ) 2 + 2 cos( t ) 2 2
4
> simplify(%);
1
2
> simplify(Torsion(<sin(t)+cos(t),cos(t)-sin(t),ln(t)>,t));
( 2 t2 + 1 ) ( t2 + 2 )
( 1 + t2 + 2 t4 )
2 t2 + 1
t2
144
> simplify(Torsion(<sin(t)+cos(t),cos(t)-sin(t),t^2>,t));
t2 ( 2 t2 + 1 )
2
2
( 3 + 2 t2 )
4 t2 + 2
> tc:=unapply(%,t);
t2 ( 2 t2 + 1 )
( 3 + 2 t2 )
tc := t
4 t2 + 2
> tc(2);
2
36 121
2178
18
> tc(100);
2
> limit(tc(t),t=infinity);
0
> SetCoordinates(cartesian[x,y,z]);
cartesianx, y, z
> F:=VectorField(<y,-x,0>);
F := y e x e
x
y
> VectorPotential(F);
145
x z e y z e
x
y
> Curl(%);
ye xe
x
y
> VectorPotential(VectorField(<-y,-z,-x>));
z 2
2 + x y e + y z e
x
y
> Curl(%);
y e z e x e
x
y
z
146
The commands that are loaded are: arc, arrow, circle, cone, cuboid, curve, cutin, cutout,
cylinder, disk, dodecahedron, ellipse, ellipticArc, hemisphere, hexahedron, homothety,
hyperbola, icosahedron, line, octahedron, pieslice, point, polygon, project, rectangle,
reflect, rotate, scale, semitorus, sphere, stellate, tetrahedron, torus, transform, translate,
vrml. The plottools package is mainly for the study of planer and solid geometry. Since
this guide is primarily for the Calculus sequence we will look at a couple of the
commands that pertain to Calculus.
As for visualizing situations in Calculus the two commands worth mentioning are
rectangle and cubiod. These two commands can help create images of Riemann sums in
both two and three dimension. For example,
> with(plots):
Warning, the name changecoords has been redefined
> with(plottools):
Warning, the name arrow has been redefined
> f:=x->x*sin(x);
f := x x sin ( x )
> display(plot(f(x),x=-4..4,y=-1..2),seq(rectangle([3+6*i/25,0],[-3+6*(i+1)/25,evalf(f(3+6*i/25))],color=yellow),i=0..24));
> display(plot(f(x),x=-4..4,y=-1..2),seq(rectangle([3+6*i/50,0],[-3+6*(i+1)/50,evalf(f(3+6*i/50))],color=yellow),i=0..49));
147
Note that we needed the plots package for the display command. If we want to visualize
Riemann sums in three dimensions we need the plottools package. In the
Student[Calculus1] package there are commands for producing two-dimensional left,
right, midpoint, lower and upper Riemann sum images. Maple does not have built-in
commands to find the three dimensional analogs to these. So if you want images of
Riemann sums in three dimensions you need to create them from scratch. For example,
the following display command plots a grid of 25 by 25 rectangular solids representing a
Riemann sum.
> with(plots):
Warning, the name changecoords has been redefined
> with(plottools):
Warning, the name arrow has been redefined
> f:=(x,y)->x*sin(y)+y*sin(x+y);
f := ( x, y ) x sin ( y ) + y sin ( x + y )
> display(plot3d(f(x,y),x=-2..2,y=-2..2,axes=boxed),
seq(seq(cuboid([-2+4*i/25,-2+4*j/25,0],[-2+4*(i+1)/25,2+4*(j+1)/25,evalf(f(-2+4*i/25,-2+4*j/25))],color=yellow),
i=0..24),j=0..24));
If you would like a little bit of a challenge read through the next command definition and
determine what it does.
> plotRS3dMP:=(f,xrng,yrng,xdiv,ydiv,boxcolor)->
display(plot3d(f,xrng,yrng,seq(args[n],n=7..nargs)),seq(seq
(cuboid([lhs(rhs(xrng))+(rhs(rhs(xrng))-lhs(rhs(xrng)))*
i/xdiv,lhs(rhs(yrng))+(rhs(rhs(yrng))-lhs(rhs(yrng)))*
j/ydiv,0],[lhs(rhs(xrng))+(rhs(rhs(xrng))-lhs(rhs(xrng)))*
(i+1)/xdiv,lhs(rhs(yrng))+(rhs(rhs(yrng))-lhs(rhs(yrng)))*
(j+1)/ydiv,evalf(subs(lhs(xrng)=(lhs(rhs(xrng))+
(rhs(rhs(xrng))-lhs(rhs(xrng)))*i/xdiv+lhs(rhs(xrng))+
(rhs(rhs(xrng))-lhs(rhs(xrng)))*(i+1)/xdiv)/2,lhs(yrng)=
(lhs(rhs(yrng))+(rhs(rhs(yrng))-lhs(rhs(yrng)))*j/ydiv+
lhs(rhs(yrng))+(rhs(rhs(yrng))-lhs(rhs(yrng)))*
148
(j+1)/ydiv)/2, f))],color=boxcolor),i=0..xdiv-1),
j=0..ydiv-1)):
The next statement uses this new command.
> plotRS3dMP(f(x,y),x=-5..5,y=-5..5,30,30,yellow,
axes=boxed);
149
Animation
Maple has a very nice feature that allow you to create a sequence of images and paste
them together to create an animation. The plots package has three built-in commands,
animate, animate3d, and animatecurve, which make the process of creating animations
easier. Unfortunately these commands are very limited. Creating an animation from
scratch is not very difficult and it allows you to have complete control over the type of
animation that is created. The basic idea is to create a sequence of plots, usually with the
seq command and any of the plotting commands, then place these plots in a display
command that has the option insequence=true. Since the display command is in the plots
package make sure you load the package into your worksheet.
> with(plots):
Warning, the name changecoords has been redefined
In the following animation we are graphing left Riemann sums using 10 to 100
rectangles. Hence we are generating 91 images and pasting them together in an
animation. Since the leftbox command is in the student package we need to load it into
our worksheet.
> with(student):
150
As you can see, animations are relatively simple to create. Place a general plot in a seq
and place all of that in a display. As with anything in Maple we can create new functions
that allow us to do more complicated animations by using a simple command. For
example, say we load the VectorCalculus package,
> with(VectorCalculus):
Warning, the assigned names <,> and <|> now have a global binding
Warning, these protected names have been redefined and unprotected: *,
+, ., Vector, diff, int, limit, series
151
> display(plotvvfTanmseq(r,rng,numfrms,vcol,seq(args[n],
n=5..nargs)),insequence=true);
> end proc:
These procedures will take a vector-valued function, graph it along with its unit tangent
vector and animate this as the unit tangent vector moves along the curve. To use them we
simply define the vector-valued function.
> r:=t-><cos(t),sin(t),t>;
r := t VectorCalculus:-`<,>`( cos( t ), sin ( t ), t )
Then to graph the curve from 0 to 15 using 20 frames in the animation with the curve
graphed in black and the vector in red, requires only.
> plotvvfTanm(r(t),t=0..15,20,red,color=black);
152
Notice the 5 panels across the top. These are subtopic panels. If you select an option that
has subtopics the subtopic listing will be displayed in the panel directly to the right. So
you keep selecting subtopics until you get to a topic that does not have a subtopic listing
and then help text will be displayed in the window below the panels. The help text
usually starts out with a statement of general syntax, followed by a list of options for the
command, followed by examples and ending with links to related topics. For example,
the help image below is for the solve command. Note that we went all the way down to
the fourth panel before we found the help we needed. This is another reason the Maple
help system is frustrating at first, you need to have an idea where the command fits in the
scheme of Maple if you have any hope of finding it. This is also why the help system
153
gets much easier to use after you have a little experience with Maple. At that point you
will have a better idea where commands are located.
Another way to invoke the help system is by using the ? command in the worksheet.
That is, at any time you can type in ? followed by the name of the command you want to
look up and press enter (no semicolon needed). This will automatically search for the
command in the help system and send you directly to the page for that command. The
unfortunate thing here is that you need to know the name of the command. For example,
the above screen was obtained by the command,
?solve
154