Professional Documents
Culture Documents
Week 11
Week 11
We can expand expressions (there are options on how you choose to make the expansion),
substitute values into expressions, make Taylor/MacLaurin series, take limits and do sums
[> subs(x=1,%);
0
[> sum(1/j^2,j=1..infinity);
pi^2/6
Note: We use percent to mean the output of the last command issued (not necessarily the
one above on the worksheet)
11.1.2 Calculus
Here we demonstrate how to take derivatives, calculate both indefinite and definite integrals
[> diff(tan(x),x);
1
1+tan(x)^2
[> simplify(%)
1/cos(x)^2
[> int(1/(1+sqrt(p)),p)
-ln(p-1)+2*sqrt(p)+ln(-1+sqrt(p))-ln(1+sqrt(p))
[> int(exp(-t^2),t=0..infinity);
sqrt(Pi)/2
Note: The simplify command can be useful as Maple does not always produce the
symbolic representation of the solution you would expect.
If things are not going well, you can clear everything with
[> restart:
If you need help with a command, for example expand, use the question mark; for example:
[> ?expand
Exact solutions
2
The solve command can be extended to solutions of systems of equations, for example:
x + 3y + z = 1, x y + z = 0, y z = 1
is solved using
[> solve(sys)
{x = -1, y = 1/4, z = 5/4}
Maples fsolve command is used to find roots of equations numerically. For example, if
we want roots of
tanh(x) = tan(x)
we use
Maple is particularly useful in helping to solve and visualise solutions to Ordinary Differ-
ential Equations (ODEs).
Lets start with examples we can do by hand this shows how Maples symbolic algebra
capability helps you solve ODEs
[> ic := y(0) = 1;
[> dsolve(ode);
y(x) = _C1*exp(-x)
3
Note: The first solution is the general solution, the second example solves the ODE with
the initial condition.
Numerical solutions
Now lets do an example which cannot be solved by hand; i.e. it must be done numerically
Note: This output represents success (it indicates that the solution is solved numerically
by a Runga Kutta 4.5 method.) Note also that the option range sets the interval that the
independent variable (x) that the solution is generated over.
In order to access the solution, we need to load a special set of plotting tools
[> with(plots):
[> odeplot(sol);
Again, we start with something we can do explicity a linear 2nd order ODE with constant
coefficients:
y (x) + 9y(x) = 0, with y(0) = 0, y (0) = 3 (11.1)
[> dsolve(ode);
y(x) = _C1*sin(3*x)+_C2*cos(3*x)
4
[> dsolve({ics, ode});
y(x) = sin(3*x)
[> odeplot(sol2)
The last two command produce the following two plots. The first is, by default, y(x)
against x. The second plot shows the variation of y (x) with y(x) which can be thought of
as speed against displacement, since ...
Remark: Equation (11.2) is the exact description of a pendulum oscillating under grav-
ity (and y(x) represents the angular excursion with time) and (11.1) is the small angle
approximation. You can see small differences between the results in Figs. 11.4.2, 11.4.2.
5
More complicated ODEs
Maple can be useful to find analytic solutions to ODEs which you find hard to do by hand.
For example:
d dy
x + xy(x) = 0, with y(0) = 1, y (0) = 0
dx dx
(non-constant coefficients... solution not obvious !) In Maple
[> dsolve(ode)
y(x) = _C1*BesselJ(0, x)+_C2*BesselY(0, x)
The Lokta Volterra Equations are represented by a pair of ODEs for two unknown
functions. They are a basic Preditor-Prey model of the evolution with time, t, of a
population of two interacting species, most easily thought of as rabbits, r(t), and foxes,
f (t).
The Lokta Volterra Equations are written:
dr df
= r(t) r(t)f (t), = r(t)f (t) f (t) (11.3)
dt dt
where , , , are model parameters which represent birth rates, death rates and inter-
actions between the two populations. For e.g. if = = 0 so that rabbits and foxes do
not interact then
dr
= r(t), r(t) = C1 et
dt
6
and
df
= f (t), r(t) = C2 et
dt
for two arbitrary constants C1 and C2 to be set by initial conditions. That is, the rabbit
population grows exponentially and the fox population dies exponentially. This is because
foxes are not eating rabbits in this model. So the interaction terms tell you how the fox
population grows with rabbits and how rabbits die due to the fox population.
[> with(DEtools):
and there are two graphical outputs. The first is the plot of the evolution of r(t) and f (t)
with time t. The second requires us to load a special Maple library ([> with(DEtools):
before plotting the so-called phase portrait. This shows r(t) against f (t) and the field
lines (lines with arrows) show the direction the solution evolves in time. The single curve
is the specific trajectory in (r(t), f (t)) space of the solution with initial conditions defined
here by ics (r(0) = 1, f (0) = 1).
Remark: We can easily find the equilibrium point where dr/dt = df /dt = 0 and the
solution remains steady and fixed for all time, by solving the nonlinear equations that result
from imposing this on (11.3). Thus we see easily that these are given by r(t) = f (t) = 0
and r(t) = / and f (t) = /.