Maple Assignment A for Mathematics 210
Developed by Jeremy Teitelbaum
# This program is called Maple. Our goal today is toplay around a bit with Maple
# to see how useful it is, and also how much fun. Before trying anything serious,
# there area few basic things you need to know.
#
# First of all, mycomments appear here mixed in with actual calculations.
# Youcan tell that I am talking, and not the computer, because I always use
# this font, and also because there is a vertical bar along the left hand side of
# the window where this text appears. Below this paragraph, you see an
# arrow > at the left hand side. That is where you can type commands to the computer. For example:
>
3+5;
8
# Notice that I typed 3+5; to thecomputer, and it gave me back "8".
# (The computer responses are marked with >).
#
# To make this work, YOUMUST END YOUR COMMAND WITH A
# SEMICOLON (;) AND YOU MUST USETHE NUMERIC KEYPAD
# ENTER KEY, AT THE FAR RIGHT OF THE KEYBOARD, TO
# ENTER YOUR COMMANDS!
#
# Now let's try something. Let's expand out (x^2-3*x+5)^10:
>
(x^2+3*x+5)^10;
2 10
(x + 3 x + 5)
>
expand(");
2 4 6 8
58593750 x + 177734375 x + 536484375 x + 601181250 x + 317551125 x
10 12 14 16 18 20
+ 87006249 x + 12702045 x + 961890 x + 34335 x + 455 x + x
19 17 3 15 13
+ 30 x + 4590 x + 358593750 x + 201636 x + 3809340 x
5 11 9 7
+ 630112500 x + 35979930 x + 179899650 x + 476167500 x + 9765625
# Notice that Maple is good at arithmetic, and that it carries out calculations exactly.
# Also notice that you use * for times, ^ for exponents.
#
# Now let's try something related to vectors. First, I'll load a vector package;
# you don't need to worry about this.
>
with(linalg):\
with(plots):\
# Now let's create a vector. Use vector([]) and commas, like this:
>
vector([1,3,5]);
[ 1, 3, 5 ]
# The "ditto" marks (") mean: the last thing the computer typed back to you.
# So if I say:
>
";
[ 1, 3, 5 ]
# I get back the vector I typed before. ("" means go back two; """ means
# go back three; that's all there are.)
#
# Also, you can assign names tothings using ":=". For example:
>
a:=vector([1,5,7]);
a := [ 1, 5, 7 ]
>
a;
a
>
crossprod(a,vector([-1,-1,-1]));
[ 2, -6, 4 ]
>
crossprod(",");
[ 0, 0, 0 ]
>
dotprod("","");
56
# As you can see, that "crossprod" and "dotprod" commands compute the
# cross product and dot product of vectors. However,Maple is much better
# than this. Remember the helix has equation:
>
r:=vector([cos(t),sin(t),t]);
r := [ cos(t), sin(t), t ]
# You can ignore the following nonsense:
>
vdiff:=proc(x,s) map(diff,x,s) end;
vdiff := proc(x,s) map(diff,x,s) end
# We can compute the derivative ofvector functions using "vdiff"
# For example:
>
vdiff(r,t);
[ - sin(t), cos(t), 1 ]
# We can also multiply vectors by a scalar using the function "scalarmul":
>
scalarmul(r,5);
[ 5 cos(t), 5 sin(t), 5 t ]
# So: dotprod,crossprod,scalarmul,vdiff. There's one more useful function,
# vnorm, which computes the magnitude of a vector:
>
vnorm:=proc(r) sqrt(simplify(dotprod(r,r))) end;
vnorm := proc(r) sqrt(simplify(dotprod(r,r))) end
>
vnorm(r);
2 1/2
(t + 1)
#
# Now let's find the unit tangent vector to the helix, which is the
# derivative of r over its magnitude:
>
rprime:=vdiff(r,t);
rprime := [ - sin(t), cos(t), 1 ]
>
vnorm(rprime);
1/2
2
# To divide rprime by its norm, we multiply by 1/sqrt(2);
>
scalarmul(rprime,1/sqrt(2));
1/2 1/2 1/2
[ - 1/2 2 sin(t), 1/2 2 cos(t), 1/2 2 ]
# Now let's find the curvature of the helix. Remember that
# the curvature is |r' x r''|/|r'|^3. First we find r'', the acceleration:
>
rdoubleprime:=vdiff(rprime,t);
rdoubleprime := [ - cos(t), - sin(t), 0 ]
# Then we find the cross product:
>
\
crossprod(rprime,rdoubleprime);
2 2
[ sin(t), - cos(t), sin(t) + cos(t) ]
# Then we divide the norms:
>
vnorm(")/vnorm(rprime)^3;
1/2
# We can also find the arc length of curves using Maple. Remember that
# arc length is found by integrating |r'|. How to integrate? Use the int
# command like this:
>
int(vnorm(rprime),t=0..5);
1/2
5 2
#
# Finally, let's draw the helix. This is done with the command "drawcurve".
# The two extra numbers are the start time and end time for the plot
# (that is, draw the curvefrom t=A to t=B).
>
drawcurve:=proc(r,a,b) spacecurve(convert(r,list),t=a..b,axes=NORMAL,color=Z) end;
drawcurve :=
proc(r,a,b)
spacecurve(
convert(r,list),t = a .. b,axes = NORMAL,color = Z
)
end
>
drawcurve(r,-4,4);
# Just to get the full effect, let's plot another helix, this one a bit elliptical:
>
r1:=vector([-t,3*cos(5*t),4*sin(2*t)]);
r1 := [ - t, 3 cos(5 t), 4 sin(2 t) ]
>
drawcurve(r1,-4,4);
# Let's compute arc length here, as well. First, we find the velocity of the
# curve:
>
vdiff(r1,t);
[ -1, - 15 sin(5 t), 8 cos(2 t) ]
# Then we find the speed using vnorm:
>
vnorm(");
4 2 10 8
(290 + 45256 cos(t) - 5881 cos(t) - 57600 cos(t) + 144000 cos(t)
6
- 126000 cos(t) )^1/2
# Sort of a mess, no? Let's try simplifying it:
>
simplify(");
4 2 10 8
(290 + 45256 cos(t) - 5881 cos(t) - 57600 cos(t) + 144000 cos(t)
6
- 126000 cos(t) )^1/2
# No luck. Still, the arc length is the integral of the speed; let's go from t=0
# to t=5:
>
int(",t=1..5);
5
/
| 4 2 10 8
| (290 + 45256 cos(t) - 5881 cos(t) - 57600 cos(t) + 144000 cos(t)
|
/
1
6
- 126000 cos(t) )^1/2 dt
# Even Maple can't handle this integral so it just gives it back to you. However,
# you can get a numerical answer by asking for a "floating point" evaluation.
# Use "evalf" like this:
>
evalf(");
46.24495933
# So we get an arc length of about 46.
# Now it'syour turn.
# You can pick a curve from the text book, or you can try this one:
# r(t)=[1-t^2,t^3-t,t]
>
r:=vector([1-t^2,t^3-t,t]);
2 3
r := [ 1 - t , t - t, t ]
# Try to use Maple to do the following things:
# 1. Find the unit tangent vector
# 2. Find the curvature
# 3. Find the arc length between t=0 and t=3
# 4. Plot thecurve.
#
# Remember the commands:
# scalarmul -- scalarmul(r,x) multiplies vector r by scalar x
# dotprod --dotprod(a,b) gives dot product of a and b
# crossprod -- crossprod(a,b) gives cross product of a and b
# vdiff -- vdiff(r,t) differentiates r by t
# vnorm -- vnorm(r) finds the magnitude of r
# drawcurve -- drawcurve(r,a,b) plots r as t runs from a to b
# int -- int(f,t=a..b) integrates function f(t) as t goes from a..b.
# evalf(int(f,t=a..b)) numerically integrates f(t) as t goes from a..b
#
# Look up above for examples on how to use them.
#
# ----------------------------Good Luck!!!
Back to Maple Assignment Cover Page