Numerical Solution of ODE
Numerical Solution of ODE
Introduction
In engineering, the subject of ordinary differential equations (ODE) not only is one of the
most beautiful parts of mathematics, but it is also an essential tool for modeling many physical
situations: spring-mass systems, resistor-capacitor-inductance circuits, bending of beams,
chemical reactions, pendulums, the motion of a rotating mass around another body, and so forth.
Numerical methods have no such limitations to only standard forms. We obtain the
solution as a tabulation of the values of the function at various values of the independe nt
variable, however, and not as a functional relationship.
I. General Problem: Find the solution of an nth ordered ordinary D.E. of the form
𝑑𝑦 𝑑2 𝑦 𝑑𝑛 𝑦
𝐹 (𝑥, , 2 , … , 𝑛 ) = 0
𝑑𝑥 𝑑𝑥 𝑑𝑥
using Numerical Method
The solution to a differential equation is the function that satisfies the differential equation
and that also satisfies certain initial conditions on the function. In solving a differential
equation analytically, we usually find a general solution containing arbitrary constants and
then evaluate the arbitrary constants so that the expression agrees with the initial
conditions. For an nth-order equation, n independent initial conditions must usually be
known.
II. Solutions
A. Analytical Solution (D.E.)
B. Numerical Solution
C. Solution
Several methods are explored in solving first-order equations, and then to show how
these same methods can be applied to systems of simultaneous first-order equations
and to higher-order differential equations.
𝑘1 = ℎ 𝑓(𝑥𝑖 , 𝑦𝑖 )
ℎ 𝑘1
𝑘2 = ℎ 𝑓(𝑥𝑖 + , 𝑦𝑖 + )
2 2
ℎ 𝑘2
𝑘3 = ℎ 𝑓(𝑥𝑖 + , 𝑦𝑖 + )
2 2
𝑘4 = ℎ 𝑓(𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘3 )
Example 1:
𝑑𝑦
= 𝑓 (𝑥, 𝑦) = −2𝑥 − 𝑦
𝑑𝑥
a) Analytical solution
𝑦(𝑥 ) = −3𝑒 −𝑥 − 2𝑥 + 2 {please verify}
TABULATION
i xi yi k1 k2 k3 k4 yi+1 Analytical
0 0 -1 0.1 0.0850 0.0858 0.0714 -0.91450 -1
1 0.1 -0.91450 0.0715 0.0579 0.0586 0.0456 -0.85620 -0.91451
2 0.2 -0.85620 0.0456 0.0333 0.0340 0.0222 -0.82250 -0.85619
3 0.3 -0.82250 0.0222 0.0111 0.0117 0.0011 -0.81100 -0.82245
4 0.4 -0.81100 0.0011 -0.0090 0.0085 -0.0181 -0.81959 -0.81096
5 0.5 -0.81959 -0.81959
Assignment 1:
Solve the initial value problem from t = 0 to 2 when y(0) = 1.
𝑑𝑦
= 𝑦𝑡 3 − 1.5𝑦
𝑑𝑡
Using the methods:
a) Analytically
b) Fourth-order R-K-M using h=0.2
V. Simultaneous ODE by R-K-M
Basis: An nth order ODE can be converted to n simultaneous 1st order ODE. For 2nd order
ODE can be converted to two (2) simultaneous 1 st order ODE.
𝑑𝑦
= 𝑓(𝑡, 𝑦, 𝑢 ) 𝑤ℎ𝑒𝑟𝑒: 𝑦 = 𝑓(𝑡) 𝑎𝑛𝑑 𝑢 = 𝑓(𝑡)
𝑑𝑡
𝑑𝑢
= 𝑔(𝑡, 𝑦, 𝑢 ) 𝑤ℎ𝑒𝑟𝑒: 𝑦 = 𝑓(𝑡) 𝑎𝑛𝑑 𝑢 = 𝑓(𝑡)
𝑑𝑡
1
𝑦𝑖+1 = 𝑦𝑖 + (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 )
6
𝑘1 = ℎ 𝑓(𝑡𝑖 , 𝑦𝑖 , 𝑢𝑖 )
ℎ 𝑘1 𝑞1
𝑘2 = ℎ 𝑓(𝑡𝑖 + , 𝑦𝑖 + , 𝑢𝑖 + )
2 2 2
ℎ 𝑘2 𝑞2
𝑘3 = ℎ 𝑓(𝑡𝑖 + , 𝑦𝑖 + , 𝑢𝑖 + )
2 2 2
𝑘4 = ℎ 𝑓(𝑡𝑖 + ℎ, 𝑦𝑖 + 𝑘3 , 𝑢𝑖 + 𝑞3 )
1
𝑢𝑖+1 = 𝑢𝑖 + (𝑞1 + 2𝑞2 + 2𝑞3 + 𝑞4 )
6
𝑞1 = ℎ 𝑔(𝑡𝑖 , 𝑦𝑖 , 𝑢𝑖 )
ℎ 𝑘1 𝑞1
𝑞2 = ℎ 𝑔(𝑡𝑖 + , 𝑦𝑖 + , 𝑢𝑖 + )
2 2 2
ℎ 𝑘2 𝑞2
𝑞3 = ℎ 𝑔(𝑡𝑖 + , 𝑦𝑖 + , 𝑢𝑖 + )
2 2 2
𝑞4 = ℎ 𝑔(𝑡𝑖 + ℎ, 𝑦𝑖 + 𝑘3 , 𝑢𝑖 + 𝑞3 )
1
𝑦𝑖+1 = 𝑦𝑖 + ℎ𝑢𝑖 + ℎ(𝑞1 + 𝑞2 + 𝑞3 )
6
𝑑2𝑦 𝑑𝑦
2
+3 + 2𝑦 = 0
𝑑𝑡 𝑑𝑡
Let
𝑑𝑦
𝑢=
𝑑𝑡
Or
𝑑𝑦
=𝑢 − − − − − − − − − − (1)
𝑑𝑡
Then
𝑑 𝑑𝑦 𝑑𝑦
( )+3 + 2𝑦 = 0
𝑑𝑡 𝑑𝑡 𝑑𝑡
𝑑𝑢
+ 3𝑢 + 2𝑦 = 0
𝑑𝑡
𝑑𝑢
= −3𝑢 − 2𝑦 − − − − − − − (2)
𝑑𝑡
1
𝑦𝑖+1 = 𝑦𝑖 + (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 )
6
1
𝑢𝑖+1 = 𝑢𝑖 + (𝑞1 + 2𝑞2 + 2𝑞3 + 𝑞4 )
6
ℎ 𝑘1 𝑞1 𝑞1
𝑘2 = ℎ 𝑓 (𝑡𝑖 + , 𝑦𝑖 + , 𝑢𝑖 + ) = ℎ [(𝑢𝑖 + )] = −0.04
2 2 2 2
ℎ 𝑘1 𝑞1 𝑞1 𝑘1
𝑞2 = ℎ 𝑔 (𝑡𝑖 + , 𝑦𝑖 + , 𝑢𝑖 + ) = ℎ [−3 (𝑢𝑖 + ) − 2(𝑦𝑖 + )] = −0.28
2 2 2 2 2
ℎ 𝑘2 𝑞2 𝑞2
𝑘3 = ℎ 𝑓 (𝑡𝑖 + , 𝑦𝑖 + , 𝑢𝑖 + ) = ℎ [(𝑢𝑖 + )] = −0.028
2 2 2 2
ℎ 𝑘2 𝑞2 𝑞2 𝑘2
𝑞3 = ℎ 𝑔 (𝑡𝑖 + , 𝑦𝑖 + , 𝑢𝑖 + ) = ℎ [−3 (𝑢𝑖 + ) − 2(𝑦𝑖 + )] = −0.308
2 2 2 2 2
Assignment 2:
Solve the differential equation
𝑑2𝑦 𝑑𝑦
2
−3 + 2𝑦 − 𝑡 = 0
𝑑𝑡 𝑑𝑡