Post on 02-Oct-2015
description
MATHEMATICAL MODELLING WITH
DIFFERENTIAL EQUATIONS
Dierential equations are equations involving derivatives.
Basic Definitions
Ordinary or Partial
Order
Linear or Nonlinear
Solution:
Exact or Approximate
Analytical or Numerical
Definitions
With an equation such as
y = 3x
the variable y is a function of the variable x; the notation to
indicate this is y = y(x). y is termed the dependent variable
and x the independent variable. This means that any value can
be given to x and the corresponding value of y will be determined
from the equation. With a dierential equation, the variablebeing dierentiated is the dependent variable.
Examples of dierential equations
dy
dx= 5y
is a dierential equation with x as independent variable and yas its dependent variable, and so is the equation
d2y
dx2 3dy
dx+ 2y = 0
A dierential equation is called ordinary if it only contains deriv-atives involving the dierentiation of a function with respect toa single independent variable. Otherwise, the equation is called
a partial dierential equation. Abbreviations commonly usedare ODE and PDE.
Examples of ODEs and PDEs
Newtons second law can be written in the form of an ordinary
dierential equation in terms of velocity as:
dv
dt=F
m
or, in terms of displacement, as
d2x
dt2=F
m
The equation representing simple harmonic motion is
md2x
dt2+ cdx
dt+ kx = 0
which is an ODE for the displacement x with respect to time t.
The two-dimensional Laplace equation, describing heat transfer
in a solid, is a PDE given by
2Tx2
+2Ty2
= 0
The dependent variable is the temperature T which depends on
its spatial position, i.e. T = T (x, y); the variables x and y are
independent.
The order of a dierential equation is the order of the highestderivative appearing in the equation. Therefore, Newtons law is
given by a first-order ODE in terms of velocity, and by a second-
order ODE in terms of displacement. The Laplace equation is a
second-order PDE.
Example 1
Consider the dierential equation:
dy
dx= 2
describing a straight line with gradient of 2. Many such lines
can be drawn in a graph, as shown below. All the family of lines
have a general equation of the form
y = 2x + k
where the constant k (the intercept) has a dierent value for eachof the lines. The above solution is thus called a general solution.
To obtain a unique solution, adequate conditions have to be spec-
ified. For instance, if we impose that y = 0 when x = 0, then the
only solution satisfying this condition is y = 2x. This solution
is called a particular solution. If all conditions are specified
at the same value of the independent variable, then the prob-
lem is called an initial-value problem. In contrast, problems
where specification of conditions occurs at dierent values of theindependent variable are called boundary-value problems.
Example 2
The second-order dierential equation:
d2y
dt2 3dy
dt+ 2y = 0
has the general solution
y = Aet +Be2t
which can be verified by direct substitution. Find the particular
solution for which y = 3 when t = 0 and dy/dt = 5 when t = 0.
Solution:
If
y = Aet +Be2t
then
dy
dt= Aet + 2Be2t
and
d2y
dt2= Aet + 4Be2t
Substituting in the original ODE gives:
Aet + 4Be2t 3Aet 6Be2t + 2Aet + 2Be2t = 0
which verifies the general solution. Substituting the first condi-
tion into the expression for y gives
3 = Ae0 +Be0 = A+B
while application of the second condition to the expression for
dy/dt gives
5 = Ae0 + 2Be0 = A+ 2B
Solving the above equations for A and B gives A = 1, B = 2.
Thus, the particular solution is
y = et + 2e2t
It can be noticed that, for second-order equations, two conditions
have to be specified for a particular solution to be found.
Linearity
A dierential equation is said to be linear if
The dependent variable and all its derivatives occur only tothe first power.
There are no products of terms involving the dependent vari-able.
There are no functions of the dependent variable or its deriv-atives which are nonlinear.
For example, the equation
d2y
dx2+ y = x2
is linear, since it does not matter that the independent variable
x is raised to the power of 2. However, the equation
dy
dx+ y2 = 0
is nonlinear because of the term y2.
Linear equations can be further classified as homogeneous or
non-homogeneous. When all the terms in a linear equation
containing the dependent variable appear on the left-hand side
of the equals sign and the terms containing the independent vari-
ables and any constants appear on the right-hand side, then the
equation is said to be homogeneous when the right-hand side
is zero and non-homogeneous when it is not. For example, the
equation
dy
dx+ y2 = 0
is homogeneous, but the equations
dy
dx+ y2 = 5
or
dy
dx+ y2 = x
are non-homogeneous.
Solution of dierential equations
A solution is said to be analytical if a closed-form expression
can be derived which allows values of the dependent variable to
be found, for any given values of the independent variable(s).
A numerical solution, usually found using the computer, will
provide values of the dependent variable at a finite number of
pre-assigned points; values at other points can only be found by
interpolation.
The most common analytical methods of solution of dieren-tial equations are Laplace transforms, separation of variables,
series expansions, Greens functions, and others.
Separation of Variables
Consider the equation
dy
dx= 2x
Multiplying both sides by dx gives
dy = 2xdx
The above equation has been separated into terms which are only
function of y, and terms which are only function of x. Integrating
both sides gives:
Zdy =
Z2xdx
y = x2 + c
where c is the constant of integration. This is the general solution
of the dierential equation.
Note that because there are integrations on both sides of the
equation we could have two constants of integration. However,
it is usual to combine these into a single constant c.
Example 3
Solve the dierential equation:
dy
dx= 4y
using separation of variables.
Solution:
dy
4y= dx
Integrating both sides gives:
ln y = 4x+ c
Example 4
Solve the nonlinear dierential equation:
ydy
dx= 4x
Solution:
ydy = 4xdx
Integrating both sides gives:
y2
2= 2x2 + c
Complementary Function and Particular Integral
Suppose we have the non-homogeneous equation
dy
dx+ y = 5
The solution to this dierential equation is of the form
y = Aex + 5
The solution to the corresponding homogeneous equation, i.e.
dy
dx+ y = 0
is given by
y = Aex
Thus, the general solution of the non-homogeneous equation is
equal to the sum of the solution of the homogeneous equation,
called the complementary function, plus another term, called
the particular integral.
The particular integral is any solution of the non-homogeneous
equation. In the above case, it can be seen that y = 5 is indeed
a solution of the non-homogeneous equation, since dy/dx = 0 in
this case.
If we consider the general form of a linear, first-order, non-
homogeneous ODE
dy
dx+ P (x)y = Q(x)
then its solution can be written in the form
y = yc + yp
where yc is the complementary function and yp the particular
integral. The complementary function is the solution of the cor-
responding homogeneous equation
dy
dx+ P (x)y = 0
while the particular solution can be determined by educated
guesswork. The usual method is to try a function of the same
form as that on the right-hand side of the equation.
Example 5
Solve the non-homogeneous dierential equation:
dy
dx+ 2y = 4x
Solution:
The corresponding homogeneous equation is
dy
dx+ 2y = 0
whose solution can be found by separation of variables to be
ln y = 2x + c
or
y = Ce2x
with C = ec. This is the expression of the complementary func-
tion yc.
Because the term on the right is 4x, the particular integral we
can try is y = A+Bx. With this solution, the non-homogeneous
equation becomes
B + 2(A+Bx) = 4x
Hence, equating coecients of x gives B = 2 and equating con-stant terms gives B + 2A = 0, and so A = 1. Therefore
yp = 1 + 2x
The solution to the non-homogeneous equation is then of the
form
y = Ce2x 1 + 2x
Runge-Kutta Methods
The Euler and Heun methods are versions of one-step approaches
calledRunge-Kuttamethods, i.e. techniques of the general form
yi+1 = yi + h (xi, yi, h)
where (xi, yi, h) is called an increment function which can beinterpreted as a representative slope over the interval.
The increment function (xi, yi, h) can be written as:
= a1k1 + a2k2 + . . . + ankn
where the as are constants and the ks are functions of the form:
k1 = f(xi, yi)
k2 = f(xi + p1h, yi + q11k1h)
k3 = f(xi + p2h, yi + q21k1h+ q22k2h)
...
kn = f(xi+pn1h, yi+qn1,1k1h+qn2,2k2h+. . .+qn1,n1kn1h)
Notice that the ks are computed from recurrence relationships
in that k1 appears in the equation for k2, which appears in the
equation for k3, and so forth. This recurrence makes RKmethods
ecient for computer calculations.
Various types of Runge-Kutta methods can be devised by em-
ploying dierent numbers of terms in the increment function.The first-order RKmethod with n = 1 is, in fact, Eulers method.
Once n is chosen, values for the as, ps and qs are evaluated by
setting the general RK equation equal to terms in a Taylor series
expansion.
Second-Order Runge-Kutta Methods
The second-order version of the general RK equation is:
yi+1 = yi + h (a1k1 + a2k2) (1)
We recall that the second-order Taylor series for yi+1 in terms of
yi and f(xi, yi) is given by
yi+1 = yi + h f(xi, yi) +h2
2f 0(xi, yi)
where f 0(xi, yi) must be determined by chain-rule dierentiation:
f 0(xi, yi) =fx+fydy
dx
Substituting the above into the previous expression:
yi+1 = yi + h f(xi, yi) +h2
2
fx+fydy
dx
(2)
The basic strategy of all Runge-Kutta methods is to use algebraic
manipulations to solve for a1, a2, p1 and q11 (in this case) that
make equations (1) and (2) equivalent.
The Taylor series for a two-variable function is defined in the
form:
g(x+ r, y + s) = g(x, y) + rgx+ s
gy+ . . .
Applying this formula to expand the expression for k2 gives:
k2 = f(xi + p1h, yi + q11k1h) =
f(xi, yi) + p1hfx+ q11k1h
fy+O(h2)
Substituting the above result into equation (1):
yi+1 = yi + a1hf(xi, yi) + a2hf(xi, yi) + a2p1h2fx+
a2q11h2f(xi, yi)
fy+O(h3)
or, by collecting terms,
yi+1 = yi + (a1 + a2) h f(xi, yi)+
h2a2p1
fx+ a2q11f(xi, yi)
fy
+O(h3) (3)
Comparing now like terms in equations (2) and (3), it can be
determined that in order for the two equations to be equivalent,
the following must hold:
a1 + a2 = 1
a2p1 =1
2
a2q11 =1
2
These three simultaneous equations contain the four unknown
constants. Because there is one more unknown than the number
of equations, there is no unique set of constants that satisfy the
equations. However, by assuming a value for one of the constants,
it is possible to determine the other three. This gives rise to a
family of second-order RK methods rather than a single version.
Assuming that the value of a2 is specified, the following equations
are then obtained for the other variables:
a1 = 1 a2 p1 = q11 =1
2a2
The two most commonly used second-order Runge-Kutta meth-
ods are the Heun method and the Ralston method. The first is
obtained making a2 = 1/2, for which a1 = 1/2, p1 = q11 = 1,
producing the equation
yi+1 = yi + h
1
2k1 +
1
2k2
with
k1 = f(xi, yi)
k2 = f(xi + h, yi + hk1)
as previously studied.
Ralstons method is obtained when a2 = 2/3, in which case
a1 = 1/3, p1 = q11 = 3/4:
yi+1 = yi + h
1
3k1 +
2
3k2
with
k1 = f(xi, yi)
k2 = f
xi +
3
4h, yi +
3
4hk1
Example
Solve the equation
dy
dx= 2x3 + 12x2 20x + 8.5
with the initial condition y = 1 at x = 0, using Ralstons method
with a step length h = 0.5.
Solution
f(x, y) = 2x3 + 12x2 20x + 8.5
y(0.5) = y(0) + 0.5
1
3k1 +
2
3k2
k1 = f(0, 1) = 8.5
k2 = f
0 +
3
4 0.5, 1 + 3
4 0.5 8.5
k2 = f(0.375, 4.1875) = 2.582
y(0.5) = 1 + 0.5
1
3 8.5 + 2
3 2.582
y(0.5) = 3.277
Proceeding one more step:
k1 = f(0.5, 3.277) = 1.25
k2 = f
0.5 +
3
4 0.5, 3.277 + 3
4 0.5 1.25
k2 = f(0.875, 3.746) = 1.1523
y(1.0) = 3.277 + 0.5
1
3 1.25 + 2
3 (1.1523)
y(1.0) = 3.101
Fourth-Order Runge-Kutta Methods
The most popular Runge-Kutta methods are fourth order. As
with the second-order approaches, there are an infinite number of
versions. The following is sometimes called the classical fourth-
order RK method:
yi+1 = yi + h
1
6(k1 + 2k2 + 2k3 + k4)
where
k1 = f(xi, yi)
k2 = f
xi +
1
2h, yi +
1
2hk1
k3 = f
xi +
1
2h, yi +
1
2hk2
k4 = f (xi + h, yi + hk3)
Example
Solve the previous problem using the classical fourth-order RK
method with a step length h = 0.5.
Solution
f(x, y) = 2x3 + 12x2 20x + 8.5
y(0.5) = y(0) + 0.5
1
6(k1 + 2k2 + 2k3 + k4)
k1 = f(0, 1) = 8.5
k2 = f
0 +
1
2 0.5, 1 + 1
2 0.5 8.5
k2 = f(0.25, 3.125) = 4.21875
k3 = f
0 +
1
2 0.5, 1 + 1
2 0.5 4.21875
k3 = f(0.25, 2.0547) = 4.21875
k4 = f(0.5, 1 + 0.5 4.21875)
k4 = f(0.5, 3.1094) = 1.25
y(0.5) = 1 + 0.5
1
6(8.5 + 2 4.21875 + 2 4.21875 + 1.25)
y(0.5) = 3.21875
which is the exact value. This was expected because the true
solution is quartic in this case, thus the fourth-order method is
able to predict the exact solution.
Systems of Equations
All methods for single equations can be extended to the solution
of systems of equations. The procedure simply involves applying
the one-step technique for every equation at each step before
proceeding to the next step.
Example
Solve the following system of first-order dierential equationsusing Euler method, assuming that at x = 0, y1 = 4 and y2 = 6.
Use a step length of 0.5.
dy1dx
= 0.5y1
dy2dx
= 4 0.3y2 0.1y1
Solution
The equations for application of Eulers method are:
y1(xi + h) = y1(xi) + h [0.5 y1(xi)]
y2(xi + h) = y2(xi) + h [4 0.3 y2(xi) 0.1 y1(xi)]
Therefore:
y1(0.5) = 4 0.5 0.5 4 = 3
y2(0.5) = 6 + 0.5 (4 0.3 6 0.1 4) = 6.9
y1(1.0) = 3 0.5 0.5 3 = 2.25
y2(1.0) = 6.9 + 0.5 (4 0.3 6.9 0.1 3) = 7.715
Example
Solve the following second-order dierential equation for a mass-spring system using Eulers method
d2x
dt2+ x = 8 cos t
assuming that x(0) = x0(0) = 0. Use a step length of 0.1 andcompare results with the exact solution x = 4t sin t.
Solution
Defining a new variable y such that:
dx
dt= x0 = y
the previous equation can be rewritten in the form
dy
dt= x+ 8 cos t
The equations for application of Eulers method are then:
xi+1 = xi + h yi
yi+1 = yi + h (xi + 8 cos ti)
Therefore:
x(0.1) = 0 + 0.1 0 = 0
y(0.1) = 0 + 0.1 [0 + 8 cos(0)] = 0.800
x(0.2) = 0 + 0.1 0.800 = 0.080
y(0.2) = 0.800 + 0.1 [0 + 8 cos(0.1)] = 1.596
x(0.3) = 0.080 + 0.1 1.596 = 0.240
y(0.3) = 1.596 + 0.1 [0.080 + 8 cos(0.2)] = 2.372
x(0.4) = 0.240 + 0.1 2.372 = 0.477
y(0.4) = 2.372 + 0.1 [0.240 + 8 cos(0.3)] = 3.112
x(0.5) = 0.477 + 0.1 3.112 = 0.788
y(0.5) = 3.112 + 0.1 [0.477 + 8 cos(0.4)] = 3.801
Example
Solve again the equation for the mass-spring system using the
classical fourth-order Runge-Kutta method.
Solution
The equations for application of the classical fourth-order RK
method are of the form:
dx
dt= f1(t, x, y) = y
xi+1 = xi + h1
6(k1,1 + 2k2,1 + 2k3,1 + k4,1)
dy
dt= f2(t, x, y) = x+ 8 cos t
yi+1 = yi + h1
6(k1,2 + 2k2,2 + 2k3,2 + k4,2)
First, we must evaluate all the k1s:
k1,1 = f1(0, 0, 0) = 0
k1,2 = f2(0, 0, 0) = 8
Next, it is necessary to calculate the values of x and y that are
needed to determine the k2s:
xi +1
2h k1,1 = 0 +
1
2 0.1 0 = 0
yi +1
2h k1,2 = 0 +
1
2 0.1 8 = 0.4
k2,1 = f1(0.05, 0, 0.4) = 0.4
k2,2 = f2(0.05, 0, 0.4) = 7.990
The process continues as follows:
xi +1
2h k2,1 = 0 +
1
2 0.1 0.4 = 0.02
yi +1
2h k2,2 = 0 +
1
2 0.1 7.990 = 0.3995
k3,1 = f1(0.05, 0.02, 0.3995) = 0.3995
k3,2 = f2(0.05, 0.02, 0.3995) = 7.970
xi + h k3,1 = 0 + 0.1 0.3995 = 0.03995
yi + h k3,2 = 0 + 0.1 7.970 = 0.7970
k4,1 = f1(0.1, 0.03995, 0.7970) = 0.7970
k4,2 = f2(0.1, 0.03995, 0.7970) = 7.920
x(0.1) = 0 + 0.1
1
6(0 + 2 0.4 + 2 0.3995 + 0.7970)
x(0.1) = 0.040
y(0.1) = 0 + 0.1
1
6(8 + 2 7.990 + 2 7.970 + 7.920)
y(0.1) = 0.797
Results for the RK method up to time t = 0.5 are shown in the
table below.
Time x (Euler) x (RK) x (Exact) y (Euler) y (RK) y (Exact)
0.1 0 0.040 0.040 0.800 0.797 0.797
0.2 0.080 0.159 0.159 1.596 1.579 1.579
0.3 0.240 0.355 0.355 2.372 2.328 2.328
0.4 0.477 0.623 0.623 3.112 3.031 3.031
0.5 0.788 0.959 0.959 3.801 3.673 3.673