AMTH247 Lecture 19
Differential Equations I
Reading: Heath §9.1, 9.2, 9.3.1
A first order differential equation is an equation
of the form
 |
(1) |
Once an initial value
is specified, we have an initial value problem.
An initial value problem has a unique solution
giving
as a function of
.
Another way of saying the same thing is that for each point
of the
-
plane there is a unique solution of equation (1)
passing through that point.
Geometrically, the differential equation can be interpreted
as saying that the solution curve through a point
has slope
at that point.
A system of first order differential equations has the form
that is, we have a system of
first order differential equations for
functions
.
An initial value problem specifies the initial values of all
functions
at the same point
:
As in the case of a single equation, an initial value problem for
a first order system has a unique solution.
It is often convenient to write the equations in vector form;
if
then the system of differential equations
can be written
where
is the vector of functions
.
The initial values can also be written in vector form
The differential equations we have studied so far contain only
first derivatives.
Higher order differential equations involve the second
and possibly higher derivatives.
An
th-order differential equation has the
form
An initial value problem specifies the initial values of
all the derivatives up to order
:
Again, such an initial value has a unique solution.
An initial value problems for a higher order equation can be
reduced to an equivalent initial problem for a system of
first order equations.
This is important in applications, because there are very
few general numerical methods applicable to higher order
equations other than those arising from numerical methods
for the equivalent first order system.
Given an
-th order equation
 |
(2) |
introduce
new variables
There are
relationships between the new variables:
which together with equation (2), which can be rewritten as,
gives a system of
first order equations for the
unknown
functions
.
The initial values for the
-th order equation
are equivalent to the following initial values for our new variables
Thus any initial value problem for an
-th order differential
equation can be converted to an initial value problem for
a system of
first order equations. Similarly, initial value
problems for systems of higher order equations can be converted
to equivalent problems for 1st order systems using the same
techniques. The method is obvious but tedious to write out.
According to Newton's laws the the position
in
the orbital plane of
a body orbiting a much larger body of mass
centered at the origin is
governed by the differential equations
where
is the gravitational constant and
.
Each of the differential equations is 2nd order
so the pair of equations is equivalent to a system of four
1st order equations.
Introducing variables
We have the relations
and
The original 2nd order equations can be written in terms
of the new variables as
and
giving our system of four 1st order equations.
The simplest numerical method for solving initial value problems
for differential equations is Euler's method.
Suppose we have an initial value problem
Choose a step-size
, then, by Taylor's approximation
The differential equation says
so that
Denote the approximate solution obtained in this way by
, then Euler's method can be written
Euler's method has a simple geometric interpretation - we approximate
the solution curve through a point
by its
tangent, which we know has the slope
.
We have seen how one step of Euler's method works.
The same procedure can be repeated over any number of steps:
start with the initial condition
and then apply Euler's method to obtain the approximations
We will use as our example the differential equation
This equation can be solved by separation of variables
to give the general solution
The initial value problem
then has the solution
We will write a Scilab function euler(f, t0, y0, dt, n)
to approximate the solution of
using Euler's method with initial conditions
= t0,
= y0, and time-step dt over n steps.
function [t,y] = euler(f, t0, y0, dt, n)
t = zeros(n+1,1)
y = zeros(n+1,1)
t(1) = t0
y(1) = y0
for i = 1:n
t(i+1) = t(i) + dt
y(i+1) = y(i) + f(t(i), y(i))*dt
end
endfunction
Applying euler to our example:
-->function y = func(t, y)
--> y = - 2*t*y
-->endfunction
-->[t,y] = euler(func, 0, 1, 0.01, 200);
-->plot2d(t, y)
We can compare the computed solution to the exact solution:
-->err = y - exp(-t.*t);
-->plot2d(t, err)
We see that the error is small enough, of the order of
,
for the computed and exact solutions to be barely distinguishable
on a graph. The shape of the error curve is not significant.
[Aside: the general shape of the error curve can be simply explained.
From the graphical interpretation of Euler's method it follows
that Euler's method overestimates the solution when the slope
of the solution is decreasing (as in the diagram) and
underestimates the solution when the slope of the solution
is increasing.
The change from one type of behaviour to the other will occur
near a point of inflection, which, in the exact solution to our
example occurs at
. There are also other types of
error to consider as well to give a complete account.]
Euler's method does always perform as well as it does in the
example above. Here is an example where it gives wildly
inaccurate results:
-->[t,y]=euler(func,0,1,1,10);
-->y'
ans =
column 1 to 9
! 1. 1. - 1. 3. - 15. 105. - 945. 10395. - 135135. !
column 10 to 11
! 2027025. - 34459425. !
The important change here was the step size. It is clear
from the derivation of Euler's method that the accuracy
should increase as the step size is decreased,
but this example shows that if the step size is too large
then totally inaccurate results can be obtained.
Euler's method for a single equation takes the form
Simply replacing the scalars
and
by vectors gives a formula
which makes sense for systems of equations
In terms of the individual equations this reads
We will adapt our previous procedure euler to deal
with systems of equations.
Again it will take the form
[t, y] = euler(f, t0, y0, dt, n)
and perform n steps of Euler's method with step size dt.
The difference now is that since we have a system of equations
we need to careful about the sizes of the variables. If we
have a system of k equations then we specify:
t: |
a column vector of size n+1. |
y: |
a matrix of size n+1 k, |
| |
the rows of y are the components at a given value
of , |
f(t,y): |
the second argument is a row vector of size k, |
| |
it returns a row vector of size k. |
y0: |
a row vector of size k. |
Our function euler is essentially the same as for a single equation,
except for the dimensions of the variables involved:
function [t, y] = euler(f, t0, y0, dt, n)
k = length(y0) // this determines the number of equations
t = zeros(n+1, 1)
y = zeros(n+1, k)
t(1) = t0
y(1,:) = y0
for i = 1:n
t(i+1) = t(i) + dt
y(i+1,:) = y(i,:) + f(t(i), y(i,:))*dt
end
endfunction
As an example we will look at the Lotka-Volterra equations which
are used to model the dynamics of predator-prey interactions.
The prey population is denoted by
and the predator population
by
. The differential equations are
The parameters
and
are the natural growth rates
of the populations, and the parameters
and
determine
the interaction between the two populations.
For our example we will use the Lotka-Volterra equations
with parameter values:
and initial conditions
Here is the function for the right hand side of our
system of equations:
-->a1 = 1;
-->a2 = 0.5;
-->b1 = 0.1;
-->b2 = 0.02;
-->function ydot = lv(t, y)
--> ydot = zeros(y)
--> ydot(1) = y(1)*(a1 - b1*y(2))
--> ydot(2) = y(2)*(-a2 + b2*y(1))
-->endfunction
By setting the values of the parameters outside the function
we could easily change them if we wanted to experiment with
different parameter values.
By setting ydot = zeros(y) we insure that ydot
has the same shape as y, (i.e. if y is a row vector
then so is ydot).
We will solve the differential equations over the interval
using steps of
.
-->[t, y] = euler(lv, 0, [100 10], 0.01, 2500);
-->plot2d(t, y)
Note that the plot works because plot2d plots each of the
columns of y and we have set things up so that the
columns correspond to the two populations
and
.
The curve with larger values is
the prey population.
Both populations show noticeable oscillations but they do
not oscillate in phase.
This has a biological interpretation.
First the prey numbers are decreasing as the predators are increasing -
the predators are eating the prey and increasing in number
because of the plentiful supply of food.
Then the predator numbers decrease as the supply of food continues
to decreases.
When the predator numbers decrease enough the prey numbers start to
increase and the cycle repeats itself.
These sorts of oscillations has been observed in
natural predator/prey populations.
Another useful graph in examples like this is a
phase-plane plot when one component of the solution,
, is plotted against the other,
, rather than plotting
each against
.
-->plot2d(y(:,1), y(:,2))
The main thing to be gained from a graph like this is
how the two populations vary with one another.
There is a clear cyclic pattern to the populations over time.
Also apparent is the fact that the maxima and minima
of the two populations do not coincide.
AMTH247 Lecture 19
Differential Equations I
This document was generated using the
LaTeX2HTML translator Version 2K.1beta (1.61)
Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -split +0 lecture.tex
The translation was initiated by amth247 on 2003-05-27
amth247
2003-05-27