Differential Equations: 4.1 Classification
Differential Equations: 4.1 Classification
Differential Equations
In the following short chapter we will summarize some easy and efficient methods for solving simple
first order Ordinary Differential Equations (ODEs). In order to use the appropriate method to obtain
the solution of a given ODE we must be able to classify the type of ODE we have at hand.
4.1 Classification
In general we classify differential equations as either partial or ordinary. For now we examine only
ordinary differential equations. In general however most models are usually comprised of several (a
system) partial or ordinary differential equations. Another reason that ordinary differential equations
(ODEs) are important is that techniques of solution for partial differential equations (PDEs) can stem
from those in ordinary differential equations. So learning how to solve ODEs will be useful by itself
or in conjuction to solving PDEs.
To choose the appropriate method of solution for a given ODE you must find out what type of
ODE you have. ODEs are categorized, among other things, as: linear/non-linear, ordinary/partial.
Also we usually refer to the “order” of the ODE as well as to whether it is “homogeneous” or not.
The following examples should be helpful in understanding how this classification system works:
dy
o dx
= −3x + 5 1st order linear non-homogeneous ODE
dy
o 3 dx = 9y 2 1st order non-linear homogeneous ODE
dy
o 3 dx +y =0 1st order linear homogeneous ODE
d2 y
o 3 dx2 + 9x3 y = 9 2nd order linear non-homogeneous ODE
dy 2
o 7 dx + 4y = 0 1st order non-linear homogeneous ODE
Try to figure out based on the examples above how naming of ODEs works. You probably understand
from the above how we determine the order of an ODE - based on the order of the derivative in
the equation. How about linearity? Do you see it? Linearity refers to the power of y. For instance
anything with y 2 and higher is non-linear. Similarly if a derivative was raised to a power, such as
dy 2
( dx ) , then it is also non-linear. Now determining whether an ODE is homogeneous or not is a
different story. The idea, as you may have noticed, is to bring all terms which include y’s on one
side of the equation. If by doing so the other side of the equation is 0 then you have a homogeneous
ODE. Otherwise you have a non-homogeneous ODE.
53
FMN050–Spring 2014. Claus Führer and Alexandros Sopasakis page 54
4. Integrate both sides. This has the effect that always the left hand side derivative disappears.
In our example this gives, Z
e y = 5e−2x + C
−2x
or rather
5 −2x
e−2x y = e +C
−2
As previously we can find the value C by substituting the initial conditions. In our example
we are given that y = 0 when x = 0. Thus substituting on the above we obtain,
5
e0 0 = − e0 + C
2
which implies that C = 5/2. Therefore our equation becomes,
5 5
e−2x y = − e−2x +
2 2
Note that this is really our solution for the ODE. We can even solve it for y as follows,
5 5
y = + e2x
2 2
FMN050–Spring 2014. Claus Führer and Alexandros Sopasakis page 56
where f (x, y) corresponds to any other term in your ODE. For instance looking back at the equation
0
xy = y 2 which we solved earlier we would rewrite it as,
0 y2
y =
x
y2
In this case therefore f (x, y) = x
. Once this is established the method iterates in the computer with
the following formula,
where here h denotes the step size in x. The iteration counter n starts at 0 and will go on until we
produce the solution required by the problem. For instance recall that the initial condition for our
ODE was provided to be y(1) = 5. In this case for n = 0 we have that x0 = 1 and y0 = 5 with which
to start the iteration of our method. The only thing which may be left up to you (unless specifically
given by the problem) is how big the step size h should be chosen to be.
Euler’s method is not exact! In fact it almost always includes errors and the solution predicted
is only an approximation to the true solution. The bigger the step size h the bigger the errors to our
solution. So if you would like to have a very accurate solution then you must take a very small step
size h and therefore you must iterate several times.
Let us assume that you would like to obtain the solution y when x = 10 for the following ODE
0
xy = y 2 , with initial condition y(1) = −1
Remember that we rewrite the ODE first. So here f (x, y) = y 2 /x. Since the step size h is not
specified you are free to choose. So if you take h = 1 then you would have to iterate Euler’s method
9 times since you are starting at x = 1 and need to reach x = 10 with this h. The following table
shows the result of the computer output and how each y is produced after each iteration of the
method,
n 0 1 2 3 4 5 6 7 8 9
x 1 2 3 4 5 6 7 8 9 10
y −1 −.5 −.42 −.37 −.34 −.32 −.31 −.29 −.28 −.2801
f (x, y) .5 .08 .04 .03 .02 .01 .01 .01 .008 .007
FMN050–Spring 2014. Claus Führer and Alexandros Sopasakis page 57
So the solution at x = 10 is y = −.2801 using a step size of h = 1. Is this correct? In fact we can
check this since we have found earlier the exact solution to be
1
y=−
ln(x) + 1
Let us compare, side by side, the approximate solution produced by Euler’s method above with this
exact solution in the table below:
x 1 2 3 4 5 6 7 8 9 10
yapp. −1 −.50 −.41 −.37 −.34 −.32 −.3104 −.2983 −.2884 −.2801
yex −1 −.59 −.47 −.41 −.38 −.35 −.3395 −.3247 −.3128 −.3028
This gives that y = −.2801 for x = 10 while the equivalent exact solution is y = .3028. The absolute
error between the two being .0227 and the relative error .075. We can not help but wonder how
much better we could possibly do if we decrease the step size h = .5. In that case of course it would
take us 18 iterations starting at x = 1 to reach x = 10. We display some of these results in the table
below:
n 0 1 2 3 4 ... 15 16 17 18
x 1 1.5 2 2.5 3 ... 8.5 9 9.5 10
yapp. −1 −.66 −.55 −.49 −.45 . . . −.3091 −.3037 −.2989 −.2944
yex −1 −.71 −.59 −.52 −.47 . . . −.3185 −.3128 −.3076 −.3028
This time the absolute error between the exact and approximate solutions for x = 10 is .0084 while
the relative error is just .000003. Huge improvement for a little bit extra work for the computer.
Usually the Runge-Kutta method is more accurate than the Euler method for the same value of the
step size h. The Runge-Kutta method goes as follows:
1
yn+1 = yn + (k1 + 2k2 + 2k3 + k4 ) where
6
k1 = hf (xn , yn )
1 1
k2 = hf (xn + h, yn + k1 )
2 2
1 1
k3 = hf (xn + h, yn + k2 )
2 2
k4 = hf (xn + h, yn + k3 )
Just so that we can see the differences between the Euler and Runge-Kutta methods we solve the
same exact ODE as before,
0
xy = y 2 , with initial condition y(1) = −1
FMN050–Spring 2014. Claus Führer and Alexandros Sopasakis page 58
for a step size of just h = 1. The results are shown in the table below:
n 0 1 2 3 4 5 6 7 8 9
x 1 2 3 4 5 6 7 8 9 10
yEuler −1 −.5 −.42 −.37 −.34 −.32 −.3104 −.2983 −.2884 −.2801
yR−K −1 −.57 −.46 −.41 −.37 −.35 −.3342 −.3199 −.3083 −.2986
yex −1 −.59 −.47 −.41 −.38 −.35 −.3395 −.3247 −.3128 −.3028
Based on these results you can make up your mind about which method is best and compare the
differences for yourself!
In this format it is not that hard to see that we can write this system into a matrix as follows,
0 1 0
0
U = AU where A = 0 0 1
2 −3 0
In this format it is now clear that our original single 3rd order ODE (4.2) has been transformed to
a reduced 1st order system of three ODEs. In general this method can take a single nth order ODE
and transform it into a system of n first order ODEs. Once you have such a system you can apply
Euler or Runge-Kutta method to solve it. The following simple example should be illustrative of this
procedure.
Example:
Solve the following ODE using Euler’s method. Obtain the solution for x = 1.
00 0
y −y =x with initial conditions: y(0) = 0, y (0) = 1 (4.4)
We start by reducing the 2nd order ODE into a system of 2 first order ODEs. To do this we follow
the procedure outlined previously. We first define 2 new variables, u1 and u2 as follows,
0
u1 = y u2 = y
To make the notation clearer we rename u1 = U and u2 = V . Thus we have the following two
equations,
0
U = F (x, U, V ) where F (x, U, V ) = V
0
V = G(x, U, V ) where G(x, U, V ) = x + U
We are now ready to apply Euler’s method for this system. Before we start though we should
also translate the initial conditions to correspond to U and V . Starting with y(0) = 0 and since
0
y = u1 = U then we have that U (0) = 0. Similarly the other initial condition y (0) = 1 becomes
0
V (0) = 1 since y = u2 = V .
Euler’s method for our system is equivalent to the following:
Un+1 = Un + hF (xn , Un , Vn )
Vn+1 = Vn + hG(xn , Un , Vn )
The following table provides the solution assuming a step size of h = .2,
n 0 1 2 3 4 5
x 0 .2 .4 .6 .8 1
U 0 .2 .4 .616 .864 1.1606
V 1 1 1.08 1.24 1.48 1.816
FMN050–Spring 2014. Claus Führer and Alexandros Sopasakis page 60
Thus when x = 1 we obtain the approximate solution to be U = u1 = 1.16 and V = u2 = 1.82. This
solves our problem! Well not really. Remember that the original question was to solve for y not
U, V, u1 or even for u2 . However we know that y = u1 . Thus y ≈ 1.16 when x = 1!
Just to check our solution if we reduce the step size to h = .1 and iterate 10 times we obtain the
solution to be y ≈ 1.24 when x = 1. If the step size becomes h = .01 and we iterate 100 times we
obtain y ≈ 1.3388. Last if we reduce the step size to h = .001 and iterate 1000 times we obtain that
y ≈ 1.3492. In other words we can safely believe that y ≈ 1.34.