Você está na página 1de 36

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 variable
being dierentiated is the dependent variable.
Examples of dierential equations
dy
= 5y
dx
is a dierential equation with x as independent variable and y
as its dependent variable, and so is the equation
d2y
dy
+ 2y = 0

3
dx2
dx

A dierential equation is called ordinary if it only contains derivatives involving the dierentiation of a function with respect to
a single independent variable. Otherwise, the equation is called
a partial dierential equation. Abbreviations commonly used
are 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 F
=
dt m
or, in terms of displacement, as
d2x F
=
dt2
m
The equation representing simple harmonic motion is
dx
d2x
m 2 + c + kx = 0
dt
dt
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
2T 2T
+
=0
x2 y 2
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 highest
derivative appearing in the equation. Therefore, Newtons law is
given by a first-order ODE in terms of velocity, and by a secondorder ODE in terms of displacement. The Laplace equation is a
second-order PDE.
Example 1
Consider the dierential equation:
dy
=2
dx
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 each
of the lines. The above solution is thus called a general solution.

To obtain a unique solution, adequate conditions have to be specified. 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 problem is called an initial-value problem. In contrast, problems
where specification of conditions occurs at dierent values of the
independent variable are called boundary-value problems.

Example 2
The second-order dierential equation:
dy
d2y

3
+ 2y = 0
dt2
dt
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
= Aet + 2Be2t
dt
and
d2y
= Aet + 4Be2t
2
dt
Substituting in the original ODE gives:

Aet + 4Be2t 3Aet 6Be2t + 2Aet + 2Be2t = 0


which verifies the general solution. Substituting the first condition 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 to


the first power.
There are no products of terms involving the dependent variable.
There are no functions of the dependent variable or its derivatives which are nonlinear.

For example, the equation


d2y
+ y = x2
2
dx
is linear, since it does not matter that the independent variable
x is raised to the power of 2. However, the equation
dy
+ y2 = 0
dx
is nonlinear because of the term y 2.

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 variables 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
+ y2 = 0
dx
is homogeneous, but the equations
dy
+ y2 = 5
dx
or
dy
+ y2 = x
dx
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 dierential equations are Laplace transforms, separation of variables,
series expansions, Greens functions, and others.
Separation of Variables
Consider the equation
dy
= 2x
dx
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:
Z

dy =

2xdx

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
= 4y
dx
using separation of variables.

Solution:
dy
= dx
4y
Integrating both sides gives:

ln y = 4x + c

Example 4
Solve the nonlinear dierential equation:

dy
= 4x
dx

Solution:

ydy = 4xdx

Integrating both sides gives:


y2
= 2x2 + c
2

Complementary Function and Particular Integral


Suppose we have the non-homogeneous equation
dy
+y =5
dx
The solution to this dierential equation is of the form

y = Aex + 5

The solution to the corresponding homogeneous equation, i.e.


dy
+y =0
dx
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, nonhomogeneous ODE
dy
+ P (x)y = Q(x)
dx
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 corresponding homogeneous equation
dy
+ P (x)y = 0
dx
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
+ 2y = 4x
dx
Solution:
The corresponding homogeneous equation is
dy
+ 2y = 0
dx
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 function 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 constant 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
called Runge-Kutta methods, 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 be


interpreted 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 RK methods
ecient for computer calculations.
Various types of Runge-Kutta methods can be devised by employing dierent numbers of terms in the increment function.
The first-order RK method 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

h2 0
f (xi, yi)
= yi + h f (xi, yi) +
2

where f 0(xi, yi) must be determined by chain-rule dierentiation:

f 0(xi, yi) =

f f dy
+
x y dx

Substituting the above into the previous expression:

yi+1

h2 f f dy
+
= yi + h f (xi, yi) +
2 x y 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) + r

g
g
+ s + ...
x
y

Applying this formula to expand the expression for k2 gives:

k2 = f (xi + p1h, yi + q11k1h) =

f (xi, yi) + p1h

f
f
+ q11k1h
+ O(h2)
x
y

Substituting the above result into equation (1):

yi+1 = yi + a1hf (xi, yi) + a2hf (xi, yi) + a2p1h2

a2q11h2f (xi, yi)

f
+
x

f
+ O(h3)
y

or, by collecting terms,

yi+1 = yi + (a1 + a2) h f (xi, yi)+

f
+ a2q11f (xi, yi) + O(h3)
x
y

f
h2 a2p1

(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 methods 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

1
1
= yi + h k1 + k2
2
2

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

2
1
= yi + h k1 + k2
3
3

with
k1 = f (xi, yi)

3
3
k2 = f xi + h, yi + hk1
4
4

Example
Solve the equation
dy
= 2x3 + 12x2 20x + 8.5
dx
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

2
1
y(0.5) = y(0) + 0.5 k1 + k2
3
3

k1 = f (0, 1) = 8.5

3
3
k2 = f 0 + 0.5, 1 + 0.5 8.5
4
4

k2 = f (0.375, 4.1875) = 2.582

2
1
y(0.5) = 1 + 0.5 8.5 + 2.582
3
3

y(0.5) = 3.277

Proceeding one more step:

k1 = f (0.5, 3.277) = 1.25

3
3
k2 = f 0.5 + 0.5, 3.277 + 0.5 1.25
4
4

k2 = f (0.875, 3.746) = 1.1523

2
1
y(1.0) = 3.277 + 0.5 1.25 + (1.1523)
3
3

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 fourthorder RK method:

yi+1

1
= yi + h (k1 + 2k2 + 2k3 + k4)
6

where

k1 = f (xi, yi)

1
1
k2 = f xi + h, yi + hk1
2
2
1
1
k3 = f xi + h, yi + hk2
2
2

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

1
y(0.5) = y(0) + 0.5 (k1 + 2k2 + 2k3 + k4)
6

k1 = f (0, 1) = 8.5

1
1
k2 = f 0 + 0.5, 1 + 0.5 8.5
2
2

k2 = f (0.25, 3.125) = 4.21875

1
1
k3 = f 0 + 0.5, 1 + 0.5 4.21875
2
2

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

1
y(0.5) = 1 + 0.5 (8.5 + 2 4.21875 + 2 4.21875 + 1.25)
6

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 equations
using Euler method, assuming that at x = 0, y1 = 4 and y2 = 6.
Use a step length of 0.5.
dy1
= 0.5y1
dx

dy2
= 4 0.3y2 0.1y1
dx
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 massspring system using Eulers method
d2x
+ x = 8 cos t
dt2

assuming that x(0) = x0(0) = 0. Use a step length of 0.1 and


compare results with the exact solution x = 4t sin t.
Solution
Defining a new variable y such that:
dx
= x0 = y
dt
the previous equation can be rewritten in the form
dy
= x + 8 cos t
dt
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
= f1(t, x, y) = y
dt

xi+1

1
= xi + h (k1,1 + 2k2,1 + 2k3,1 + k4,1)
6
dy
= f2(t, x, y) = x + 8 cos t
dt

yi+1

1
= yi + h (k1,2 + 2k2,2 + 2k3,2 + k4,2)
6

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 +

yi +

1
1
h k1,1 = 0 + 0.1 0 = 0
2
2

1
1
h k1,2 = 0 + 0.1 8 = 0.4
2
2

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 +

yi +

1
1
h k2,1 = 0 + 0.1 0.4 = 0.02
2
2

1
1
h k2,2 = 0 + 0.1 7.990 = 0.3995
2
2

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

1
x(0.1) = 0 + 0.1 (0 + 2 0.4 + 2 0.3995 + 0.7970)
6

x(0.1) = 0.040

1
y(0.1) = 0 + 0.1 (8 + 2 7.990 + 2 7.970 + 7.920)
6

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

Você também pode gostar