Maple Commands With Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

MA 221 – Maple Commands with Notes and Tips

1 Solving Differential Equations


Command: dsolve({ode,ic})

The “ode” is the (ordinary) differential equation and “ic” is the initial condition(s) (if they exist).
If there aren’t initial conditions, you can just use the command “dsolve(ode)”.

Example: dsolve({y 0 (x) + 2y(x) = cos(2x), y(0) = 1})

Troubleshooting:
• Make sure you use the (independent) variable when defining the DE. An expression like
y 0 + 2y will not work; Maple needs to know explicitly what the function and variable (i.e.
dependent and independent variables) are.
• NEVER use quotation marks for two derivatives; always use the appropriate number of
apostrophes.
• Use * for multiplication whenever you are multiplying two letters. For example , if k is an
unknown parameter and t is your (independent) variable, type cos(k ∗ t); otherwise, Maple
will treat kt has (another) unknown variable.
• Use restart if you already solved for a function with the same name to avoid errors.
• Typing y := dsolve(...) will not save the solution in a form that you can evaluate, plot,
etc. Instead, first use the dsolve command by itself. Then in the next line, type “y :=”
followed by either (1) copying and pasting the solution from the previous line or (2) typing
rhs(%) (to recall the right-hand side of the previous line).

2 Plotting Solutions to Initial-Value Problems


You can (try) to have Maple solve an initial-value problem analytically (using dsolve as out-
lined above) and then plot the solution using the plot command. However, the following plotting
method is more versatile; it can be used when there isn’t an analytic solution (Maple will approx-
imate it numerically). The “ode” is the differential equation and “ic” is the initial conditions.

Command: with(DEtools):
DEplot(ode, x(t), t = a..b, [[ic]])

Example: DEplot(x00 (t) + 4x(t) = t3 , x(t), t = 0..10, [[x(0) = 2, x0 (0) = 0]])

Troublshooting:
• Remember to include the package DEtools.

MA221 1 c Dr. Tracy Weyand


3 Euler’s Method
3.1 Option 1
Command: with(Student[NumericalAnalysis]):
Euler(ode,ic,t=a, numsteps = n)

This command will preform Euler’s Method to numerical estimate the solution of a first-order
initial-value problem at a particular point. The “ode” is the (ordinary) differential equation and
“ic” is the initial condition. The point “a” is the place at which you want to estimate the solution
and “n” is the number of steps/times Euler’s approximation is preformed. Note that if you are
given “h” (a step size), you must convert this to figure out “n”. In particular,
a − x0
n=
h
where x0 is where the initial condition occurs.

Troubleshooting

• You must write the ode in the form x0 (t) = f (t, x).

3.2 Option 2
Command: x:=dsolve({ode, ic}, x(t), numeric, method=classical[foreuler], stepsize=∆t)

This command will create a vector of values; the jth entry is the approximate solution at the jth
step point tj . Here “ode” is the (ordinary) differential equation and “ic” is the initial condition.
Make sure that you name/save this vector to recall its information later; above and below, I saved
it as x.

1. To find the estimated value of the solution at a step point tj , type x(tj ).

2. To plot the numerical estimation:


Command: with(plots):
odeplot(x, [t,x(t)], a..b)

For a < t < b, this will plot the points (tj , x̃(tj )) where tj is a step point and x̃(tj ) is
the Euler approximation of the solution at that point; those points will be connected with
(approximation) lines.

MA221 2 c Dr. Tracy Weyand


4 Improved Euler Method
Command: x:=dsolve({ode, ic}, x(t), numeric, method = classical[heunform], stepsize=∆t)

This command will create a vector of values; the jth entry is the approximate solution at the jth
step point tj . Here “ode” is the (ordinary) differential equation and “ic” is the initial condition.
Make sure that you name/save this vector to recall its information later; above and below, I saved
it as x.

1. To find the estimated value of the solution at a step point tj , type x(tj ).
2. To plot the numerical estimation:
Command: with(plots):
odeplot(x, [t,x(t)], a..b)

For a < t < b, this will plot the points (tj , x̃(tj )) where tj is a step point and x̃(tj ) is the
improved Euler approximation of the solution at that point; those points will be connected
with (approximation) lines.

5 Plotting Slope Fields


5.1 Option 1
Command: with(DEtools):
dfieldplot(ode, x(t), t = a..b, x = c..d)

Here “ode” is the (ordinary) differential equation, t is the (independent) variable, and x(t) is the
solution to the differential equation. This command will plot a slope field for the range a ≤ t ≤ b
and c ≤ x ≤ d.

Example: dfieldplot(x0 (t) = x2 (t) − x(t) − 2, x(t), t = 0..10, x = −3..3)

5.2 Option 2
Command: with(DEtools):
DEplot(ode, x(t), t = a..b, x= c..d, arrows = large)

Once again, “ode” is the (ordinary) differential equation, t is the (independent) variable, x(t) is
the solution to the differential equation, and the command will plot a slope field for the range
a ≤ t ≤ b and c ≤ x ≤ d.

Example: DEplot(x0 (t) = x2 (t) − x(t) − 2, x(t), t = 0..10, x = −3..3, arrows = large)

Troublshooting:
• For either option, remember to include the package DEtools.

MA221 3 c Dr. Tracy Weyand


6 Matrix Algebra
Do not forget to include the package with(LinearAlgebra):
A := Matrix([[r1 ],[r2 ],. . .,[rn ]])
Define a matrix where rk = ak1 , ak2 , . . . , akm for an n × m matrix
(or alternatively, see the “Matrix” palette on the left-hand side)
Row Echelon Form GaussianElimination(A) or see “Solvers and Forms”
Reduced Row Echelon Form ReducedRowEchelonForm(A) or see “Solvers and Forms”
Inverse A−1 or under “Standard Operations”
Transpose Transpose(A) or under “Standard Operations”
Determinant Determinant(A) or under “Standard Operations”
Eigenvalues Eigenvalues(A) or under “Eigenvalues, etc”
Eigenvectors(A) or under “Eigenvalues, etc”
Eigenvectors Outputs a vector of the eigenvalues and a matrix of the
eigenvectors (in the same order)

Note: To multiply matrices in Maple, use a period (.) instead of an asterisk (*).

7 Important Review
• int(f,x) – To integrate a function

• diff(f,x) – To differentiate a function

• plot(f,x=0..a) – To graph a function

• solve(f=a) – To solve an equation for an unknown variable

• subs(x=a,f) – To substitute a specific number into an equation for a variable

• evalf(expression) – To get a decimal approximation of a numerical expression

This list is just a highlight of some commands that will be used a lot in this course; this isn’t
necessarily everything you will need to know. On the Mathematics Course Information Repository
Moodle page, look in the Supplementary Materials folder under MA 111, 112, and 113 (Calculus
I, II, and III) to see all the Maple commands you are expected to already know.

In general, look (1) in the help menu on Maple, (2) on the Maple page of our Moodle course,
(3) on Moodle in the Mathematics Course Information Repository course under the corresponding
calculus course, or (4) ask me if you need assistance using any of these commands.

MA221 4 c Dr. Tracy Weyand

You might also like