Maple Lab Manual by Donald Hartig

Maple Lab Manual
by
Donald Hartig
This manual contains labs for use in conjunction with Math 344.
The first Chapter introduces the Maple syntax for handing problems in calculus and differential equations.
The accompanying lab will give you the opportunity to practice using Maple to calculate some of the things
that you learned about in Math 241 and 244 (or their equivalent).
Subsequent Chapters develop the tools needed to handle problems in Laplace transforms, power series
solutions for variable coefficient linear odes and the special functions that they generate, and Fourier
analysis.
Material contained herein is copyrighted by me for the exclusive use of the students in my two sections of Math 344, Fall Quarter,
Academic Year 2014-2015, at Cal Poly.
San Luis Obispo
September, 2014
Math 344, Maple Lab Manual
Chapter 1: Intro to Maple
Calculus and ODES
Chapter 1. An Introduction to Maple
Maple can be used to deal with all of the topics in this course. You will learn to use Maple and have limited
access to Maple on exams. Each Chapter begins with explanations and examples illustrating how Maple
works. A Lab follows with tasks requiring the use of the procedures discussed in the Chapter. Bring this
manual and all other Maple handouts to your lab sessions.
Math Mode
When Maple opens you are in Math mode characterized by a slanted input cursor. Maple is waiting for you
to make a Math entry. The following three examples are related to Laplace transforms.
N
0
t eKs t dt = t/N
lim
K
t s eKs t C eKs t K 1
s2
N
t eKs t dt assuming s O 0 =
0
1
s2
1
(The laplace procedure is in the inttrans package, more about it later.)
s2
Each of these equations was obtained by typing the left hand side (henceforth referred to as the input), and
then pressing the key combination Command-equals to get the equals sign and the right hand side (the right
hand side is called the output). How to enter a definite integral is explained at the end of this chapter.
inttrans laplace
t, t, s =
Text Mode
Maple can also be used in Text mode where it serves as a text editor.
To switch from Math mode to Text mode press Command-T.
Text mode is characterized by a vertical input cursor.
To switch from Text mode to Math mode press Command-R.
Do not mix modes in the same paragraph.
• As a general rule, once in Text mode stay in Text mode. If you want to make a Math entry,
press the [return] key ([enter] on a PC) to move to a new paragraph, then press Command-R.
• Similarly, as a general rule, once in Math mode stay in Math mode. If you want to make a Text
entry, press the [return] key to a new paragraph, then press Command-T.
Maple as a Calculator: The evalf Procedure
Maple can be used as a calculator. However, unlike many calculators, Maple always gives an exact answer
when the input contains exact values (i.e. no decimals). The following equation was obtained by typing the
left side and then pressing Command-equals. Maple refers to this as in-line evaluation.
188
44414
234 C
K 884 =
K 2 221
189
189
To get a decimal approximation to the output apply the evalf procedure to the expression or right-click on
the output and choose Approximate on the contextual menu that appears.
A 20-digit approximation obtained by right-clicking on the exact output is displayed below.
at 20 digits
188
44414
234 C
K 884 =
K 2 221
205.26257150007198366
189
189
The next Math entry shows how to use evalf to get a 15-digit approximation to the same number.
188
evalf 234 C
K 884 , 15 = 205.262571500072
189
The default number of digits for evalf is 10. See the following approximation.
page 1
Math 344, Maple Lab Manual
Chapter 1: Intro to Maple
Calculus and ODES
evalf p = 3.141592654
If a 200 digit approximation for p is needed Maple will supply it, see below.
• The number p is entered by typing pi and pressing the escape key followed by the [return] key.
We will refer to this simply as [esc] [return].
The output to the following entry appears on the next line because the entry was processed by pressing the
[return] key instead of the key combination Command-equals. Note that the output is labeled (1). This
label can be used to refer to the output in a subsequent Math entry.
evalf p, 200
3.141592653589793238462643383279502884197169399375105820974944592307816406286\
2089986280348253421170679821480865132823066470938446095505822317253594081\
284811174502841027019385211055596446229489549303820
(1)
Decimal output can also be obtained by using decimals in the input.
188.0
234 C
K 884.0 = 205.2625715
189
This does not work when an exact constant like p appears in the expression to be simplified.
3.3
pC
= p C 1.500000000
2.2
Apply evalf to get an approximate value. A 4-digit approximation is obtained below.
evalf %, 4 = 4.642
(A percent sign in a Math input refers to the most recent Maple output.)
The Usual Functions are Entered in the Usual Way
The standard functions of calculus are typed into a Math entry in the usual way.
• Always enclose the function's arguments in round parentheses ( ) .
• Warning: Make sure that there are no spaces between a function name and the left parenthesis
enclosing its arguments.
The next entry is a sequence of three trig expressions. The output is on the next line, and labeled, because
the [return] key was pressed to process the input. Maple is always in radian mode when it evaluates trig
functions.
sin p / 4 , cos 3 p , arctan 1
1
2
2 , K1,
1
p
4
(2)
Since the input is a sequence of three items, the output is also.
The jth term in the output sequence labeled (2) can be obtained by referring to it as (2) j . See the next
entry where the arcsine function is applied to the second term in sequence (2).
1
arcsin (2) 2 = K p
2
• The label (2) was entered by pressing Command-L and typing 2 in the ensuing dialogue.
The absolute value function is invoked using vertical slashes, ln denotes to the natural logarithm function.
ln K3.4 C 2 = 0.3364722366
The exponential function can be entered as exp.
exp 3.2 = 24.53253020
Type exp [esc] [return] to obtain a Math input that looks like what you are accustomed to see in math
books.
e3.2 = 24.53253020
page 2
Math 344, Maple Lab Manual
Chapter 1: Intro to Maple
Calculus and ODES
Two Dimensional (2d) Plots
Before making a 2d plot we set the default plot color to black and reduce the size of the font for the axes.
plots setoptions color = black, font = times, roman, 8 , labelfont = times, roman, 8
The plot follows. Pressing Command-equals causes the output to appear on the same line as the input.
plot eKt sin p t , t = 0 ..4 =
0.6
0.4
0.2
0
K0.2
1
2
t
3
4
The next plot output is centered below the plot entry because the input was processed by pressing [return]
instead of Command-equals.
plot
eKt, KeKt, eKtsin p t
, t = 0 ..4, linestyle = 2, 2, 1
1
0.5
0
K0.5
1
2
t
3
4
K1
Three curves are drawn above, one for each of the expressions appearing in the first argument in the plot
procedure which is a list containing the expressions to be plotted.
• A list in Maple is a sequence enclosed in square brackets:
. Never, never, never use square
brackets to organize a complicated input expression because square brackets are reserved
exclusively for lists, or to enter a term in a list, or to make a subscripted variable.
The line style equation in the last plot entry assigns the styles numbered 2 (dot) and 1 (solid, the default line
style) to the three curves. There are 7 line styles in all: solid (1), dot (2), dash (3), dashdot (4), and three
more.
The Number e
A few more words about the number e are in order. As mentioned above, the exponential function is entered
by typing exp, (then pressing [esc] [return] if desired). See the derivative calculation below.
d
eKcos t = sin t eKcos t
dt
If you just need the number e, type e and then press [esc] [return]. If you do not do this then you will be
entering the variable named e instead of the number e. See the next Math entry where evalf is applied to the
list containing the variable e and the number e.
evalf e, e , 6 = e, 2.71828
And here are two more integrals. The first one has an incorrectly entered exponential function.
1
e3 x
e3 x dx =
(This integrand was entered incorrectly as e ^ 3x.)
3 ln e
1 3x
e3 x dx =
e
(This integrand was entered correctly as exp [esc] [return] 3x.)
3
The Number p
The number p can be entered by typing pi [esc] [return]. It can also be entered by just typing Pi.
evalf
p, Pi , 6 = 3.14159, 3.14159
If you type pi, without pressing [esc] [return], then Maple interprets it as the Greek letter p.
evalf pi = p
page 3
Math 344, Maple Lab Manual
Chapter 1: Intro to Maple
Calculus and ODES
Roots
A square root can be entered, for example, as sqrt 144 . Type sqrt [esc] [return] to obtain
.
sqrt 144 , 144 = 12, 12
To enter a cube root use a fractional exponent.
at 5 digits
8 1 /3 = 8 1 /3
2.0000 (Note that Maple did not automatically simplify the output.)
Integrals
An indefinite integral can be entered like this.
int 4 x sin 2 x , x = sin 2 x K 2 x cos 2 x
To enter the integral using an integral symbol type int [esc] and choose the appropriate template by arrowing
down on the contextual menu and pressing [return].
4 x sin 2 x dx = sin 2 x K 2 x cos 2 x
A definite integral can be entered like this.
int 4 x sin 2 x , x = 0 ..3 = sin 6 K 6 cos 6
Or, an integral template can be used. Type int [esc], then and choose the definite integral template. Tab from
position to position in the template.
3
4 x sin 2 x dx = sin 6 K 6 cos 6
0
If one of the limits of integration is in decimal form, then Maple will evaluate the integral numerically and
return a 10-digit approximation.
2.0
xx dx = 2.833876745
0
Compare the output above to the output below where both limits are in exact form.
2
2
xx dx =
0
xx dx
(Maple cannot evaluate this integral exactly, so it returns the unevaluated integral.)
0
Derivatives
A prime (apostrophe) on an expression denotes differentiation with respect to x.
1
x 1 C tan x 2
x ln x K x / tan x ' = ln x C 1 K
C
tan x
tan x 2
If a prime is attached to a variable, then Maple assumes that the variable represents a function of x.
d
y' =
y x
dx
To differentiate with respect to some other variable type diff [esc] and choose the appropriate derivative
template as shown below.
d
z C tan z = 2 C tan z 2
(Maple differentiates tan z as 1 C tan 2 z .)
dz
An Initial Value Problem
The next few math entries solve an initial value problem. The solution equation is assigned the name soln.
Output is suppressed by terminating it with a colon. The solution and the driver, cos 3 x , are then plotted,
and then the solution is displayed (using three-digit accuracy).
soln d dsolve y ''C 0.2 y 'C 9.01 y = cos 3 x , y 0 = 1, y ' 0 =K1 :
plot rhs soln , cos 3 x , x = 0 ..16, linestyle = 1, 2 , caption = "The driver is the dotted curve" ;
evalf soln, 3
page 4
Math 344, Maple Lab Manual
1
0.5
0
K0.5
K1
Chapter 1: Intro to Maple
2
4
6
8
x
10
Calculus and ODES
12
14
16
The driver is the dotted curve
y x = K1.97 eK0.100 x sin 3. x C 0.972 eK0.100 x cos 3. x C 1.67 sin 3. x C 0.0278 cos 3. x
(3)
Maple's dsolve Procedure
The procedure in Maple that solves differential equations is named dsolve. To obtain a general solution
make an entry like this.
dsolve y ''C y = sin x
1
1
y x = sin x _C2 C cos x _C1 C
sin x K
cos x x
(4)
2
2
To obtain the solution satisfying specific initial conditions make an entry like this.
dsolve y ''C y = sin x , y 0 = 1, y ' 0 = 2
5
1
y x =
sin x C cos x K
cos x x
2
2
Note that the ode and the initial conditions are placed inside of set brackets
(5)
.
Using dsolve to obtain a series solution
The next entry uses dsolve to generate a series solution of order 4 for a second order linear ode with a
variable coefficient.
dsolve x y ''C y = 0, y x , series, order = 4
1
1 2
1
1 2
1 3
y x = _C1 x 1 K
xC
x K
x3 C O x4 C _C2 ln x
Kx C
x K
x
2
12
144
2
12
3 2
7 3
C O x4 C 1 K
x C
x C O x4
4
36
(6)
The exact general solution to this ode can be expressed in terms of Bessel Functions. We will have more to
say about these functions in a few weeks.
dsolve x y ''C y = 0
y x = _C1
x BesselJ 1, 2
x
C _C2
page 5
x BesselY 1, 2
x
(7)
Math 344, Maple Lab Manual
Chapter 1: Intro to Maple
Calculus and ODES
Chapter 1 Procedures
Math Entry (Example)
Typical Application
Calculation
Single Integral
Approximate the length of one leaf of
the 4-leafed rose r = 2 sin 2 q .
f q d 2 sin 2 q : Function definition
Type int then [esc] and choose the
appropriate template. Tab from position to
position.
p/2
f q
L=
Type int then [esc] and choose the
appropriate template for the outer integral.
Tab to the integrand position and type int
then [esc] and choose the template for the
inner integral. Tab from position to
position.
Triple Integral
Type int then [esc] and choose the
appropriate template for the outer integral.
Tab to the integrand position and type int
then [esc] and choose the template for the
middle integral. Tab to the integrand
position of the middle integral and type int
then [esc] and choose the template for the
inner integral. Tab from position to
position.
Derivative
Use the prime notation to differentiate
either a function or an expression in the x
variable as shown below.
sin x4
1 C x2 C x4
'
4 cos x4 x3
sin x4 4 x3 C 2 x
K
4
2
x Cx C1
x4 C x2 C 1 2
fsolve %, x = 0.1 ..2 = 1.460759072
The prime notation can be used to enter an
ode when x is used for the independent
variable.
The following equation models an
undamped mass-spring system driven near
its resonance frequency.
dq
L = 2.115878306
Approximate the volume of the solid
region that is above one leaf of the 4leafed rose r = 2 sin 2 q and inside
the sphere centered at the origin of
radius 2.
p / 2 2 sin 2 q
V=
0.0
4 K r 2 r dr dq
0
V = 2.411012427
Hint. The equation of the sphere in
cylindrical coordinates is z 2 C r 2 = 4.
Approximate the mass of the solid
region that lies above one leaf of the
4-leafed rose r = 2 sin 2 q and inside
of the sphere centered at the origin of
radius 2, if its mass density is
d r, q, z = z 2
Find the maximum value of
x sin 2 x on the interval 0, p .
Referring to the plot on the right,
show that the graph of x sin 2 x has
two inflection points in this interval.
fsolve x sin 2 x '' = 0, x = 0 ..p / 4
0.5384369932
fsolve x sin 2 x '' = 0, x = p / 4 ..p
1.821798584
This is the expression's first positive
critical point.
A Differential Equation in the x Variable
2
C f' q
0.0
x
1
dx =
arctan x2
2
x4 C 1
Double Integral
2
p / 2 2 sin 2 q
0.0
y ''C 4.5 y x = cos 2 x
Plot solution and comment on the
"beats".
y ''C 4.5 y = cos 2 x
d2
y x C 4.5 y x = cos 2 x
dx2
z 2 r dz dr dq
0
0
M = 2.213254386
f x d x sin 2 x : Function definition
X d fsolve f ' x , x = 0 ..p / 2
1.014378919
f X = 0.9098528706
plot
f x , X, f X
, x = 0 ..p, style
= line, point ,
symbolsize = 35, view = 0 ..p,K2.5 ..1
1
0
K1
K2
Solve the equation modeling an
undamped mass-spring system driven
near its resonance frequency. Use the
zero-state initial conditions.
4 K r2
M=
p
8
p 3p p 5p
4 8 2 8
7p p
8
x
dsolve y ''C 4.5 y = cos 2 x , y 0 = 0, y
' 0 =0
3
y x = K2 cos
2 x C 2 cos 2 x
2
plot rhs % , x = 0 ..100
3
1
K1
K3
20
40
60
80
100
x
The system is close to resonance.
page 6