Maple: An Introduction

Math 244
Page 1
Maple Intro
Maple: An Introduction
In the computer lab you will use Maple, a computer algebra system, to help you understand many of the
things we will do this quarter. After a few introductory sessions you will
1. Solve first order odes and obtain plots of exact and approximate solution curves.
2. Generate solutions to second-order linear odes and make phase-plane plots.
3. Manipulate vectors and matrices.
4. Use vectors and matrices to solve linear systems of first order equations.
Input and Output
Maple works on the paradigm of input and output. The user provides the input, Maple provides the output.
Make Inputs at an Input Prompt
Maple input must be entered at an input prompt. See below.
O
Such a prompt appears within what is called an Execution Group. To get one, choose Execution Group
on the Insert Menu or
• Press Command-J to obtain an Execution Group after the cursor position
• Press Command-K to obtain an Execution Group before the cursor position.
To obtain a region for text enter an Execution Group and then
• Press Command-T to convert an Execution Group into a Text Group.
Two Input Styles
Maple allows the user to employ two input styles.
Maple Notation
One input style is called Maple Notation. Text appears bold and red. Mathematics is entered in a one
dimensional typewriter style. Here, for example, is how to add 5 / 2 and 7 / 33 using Maple Notation.
O 5/2 + 7/3^3 ;
149
54
(1)
A math entry in Maple Notation must terminate with either a semi-colon or a colon. Send it to Maple for
processing by pressing the [return] key. Observe that the output above is exact and has been assigned the
label (1) for future reference. An approximate math input will yield an approximate (decimal) output. The
default accuracy is 10 digits.
O 5.0/2 + 7/3^3 ;
2.759259259
(2)
Decimal output can also be obtained by applying the evalf procedure to an expression. See the next entry
where evalf is used to obtain a 20 digit approximation to the number ep .
O evalf( exp(1)^Pi , 20) ;
23.140692632779269008
(3)
Math 244
Page 2
Maple Intro
In Maple Notation the number e is entered as exp 1 and the number p is entered as Pi .
2-D Math Notation
Maple's second input style is called 2-D Math Notation. It is the default style in a Maple Worksheet. The
next two entries were made by typing the same symbols displayed in the first two inputs, using the right
arrow key to navigate out of the fraction and the out of the exponent.
O
O
5
7
C 3
2
3
149
54
(4)
2.759259259
(5)
5.0
7
C 3
2
3
The number ep in the next input was entered as follows: Type the letter e and press the escape key [esc],
and then press [return] to choose the first item on the contextual menu. Press ^ (shift-6) to move the
cursor to the exponent position, type pi then press [esc] and [return] to choose the first item in the
contextual menu.
O evalf ep , 20
23.140692632779269007
(6)
As you can see, no punctuation is required for a 2-D math input. However, using punctuation allows one
to make several entries at an input prompt.
Several Entries, Output Suppressed, Use of %
The next input contains five math entries, the first and the third terminate in colons (suppressing the
output) and the other three terminate in semi-colons so the outputs are shown. The last output gets a label.
O 1C
1
1
1
1
1
1
1
1
1
1
: 1 C C ; 1 C C C : 1 C C C C ; evalf %
2
2
3
2
3
4
2
3
4
5
11
6
137
60
2.283333333
(7)
The final math entry in the input above applies the evalf procedure to the previous output ( 137 / 60 ).
• A percentage sign in a Maple input refers to the last item that was produced as a Maple output,
two percentage signs refers to the penultimate output, and so on.
The preceding examples show how arithmetic calculations are made. The following examples show how
Maple makes calculus computations.
Calculus in Maple, the Assignment Operator
First some calculus in Maple Notation, beginning with the definition of a function.
O f := x -> x*sin(2*x) ;
f := x/x sin 2 x
(8)
Math 244
Page 3
Maple Intro
Read the input as "f is assigned as the name of the transformation that takes x to x*sin(2*x)".
• The combination of a colon and an equals sign, := , is called the assignment operator.
Once a function is defined we can differentiate it by applying the diff operator.
O diff( f(x), x) ;
sin 2 x C 2 x cos 2 x
And here is how to integrate f using Maple Notation.
O int( f(x), x) ;
1
1
sin 2 x K x cos 2 x
4
2
(9)
(10)
Calculus in 2-D Math Notation
Using 2-D Math Notation most calculus operations are performed by creating the same symbols that you
used in calculus. For example, a function such as g x = sin x / x , can be defined as follows. Note the
use of the assignment operator in the definition of g.
O g x d
sin x
x
g := x/
sin x
x
(11)
To differentiate g simply enter g' x . The "prime" is the apostrophe symbol.
O g' x
cos x
sin x
K
x
x2
(12)
To obtain the second derivative type two apostrophes for two primes.
O g'' x
sin x
2 cos x
2 sin x
K
K
C
2
x
x
x3
(13)
• Be careful: To get the second derivative type two apostrophes not a double quote symbol.
To obtain an integral for g type the "word" int, press [esc], and choose the indefinite integral template on
the contextual menu that appears. Type g(x) in the selected integrand position and then tab to the
differential position and type x.
O
g x dx
Si x
(14)
The function Si is called the Sine Integral. It is defined so that Si x is the antiderivative of sin x / x that
has the value 0 when x = 0 .
A Maple Plot
The next entry shows how to plot the graph of g and its antiderivative, Si .
O plot
g x , Si x , x =K3 p ..3 p, tickmarks = spacing p , spacing 0.5
Math 244
Page 4
Maple Intro
1
K3 p
Kp
K2 p
The graph of Si x
p
K1
2p
3p
x
The following rules apply when using the plot command.
1. The function(s) to be plotted must appear first. If there are more than one put them inside of a
pair of square brackets (Maple calls this a list).
2. The horizontal plot range must come next, in the form x = a ..b (x is the independent variable).
3. An optional tickmarks equation can be used to define the spacing for the tickmarks on the
horizontal and vertical axes. The spacing settings must also be in list form.
4. Text and arrows can be added by clicking on the plot and selecting "Drawing" on the contextual
menu bar that appears directly below the button bar at the top of the Worksheet.
A Differential Equation, Its Solution Formula and Graph
A freshly baked pie (Temperature 300 degrees F) is set to cool at noon in the kitchen (Temperature 70
degrees F). The pie reaches the temperature of 270 degrees in 8 minutes. Assuming Newton's Law of
Cooling applies, how long must we wait until the pie's temperature is 100 degrees F?
According to Newton, the pie's temperature T t exactly t minutes after noon satisfies the differential
equation T ' t = k$ T t K 70 . Since T 0 = 300 , k ! 0 . The solution, in terms of k, can be found
by applying Maple's dsolve procedure to the set containing the differential equation and the initial
condition. The solution is assigned the name Soln.
O Soln d dsolve
T ' t = k$ T t K 70 , T 0 = 300
Soln := T t = 70 C 230 ek t
(15)
The value of k is found using the fact that T 8 = 270 . The substitute procedure, subs, will produce the
desired equation, and the solve procedure will solve the equation for k. Then use subs again to obtain the
solution formula containing the correct value of k. We name it FinalSoln.
O subs t = 8, T 8 = 270, Soln : solve %, k
: FinalSoln d subs %, Soln
FinalSoln := T t = 70 C 230 e
1
20
ln
8
23
t
(16)
The pie can be eaten about 117 minutes after being removed from the oven.
O plot rhs FinalSoln , 100 , t = 0 ..205, Temp = 0 ..300, linestyle = 1, 2 ;
Eat the pie when t = solve subs T t = 100.0, FinalSoln , t $minutes
300
Temp
200
100
0
0
50
100
t
150
200
Eat the pie when t = 116.5915065 minutes
(17)