DE Numerical PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

Solution of Ordinary

Differential Equation
Numerical Methods-Euler and Modified Euler
Methods
Runge-Kutta Method
Differential Equation
Basic Idea of Numerical Solution
Numerical Solution
of Ordinary Differential Equation
• A first order initial value problem of ODE may be written in the form
y ' (t ) = f ( y, t ), y ( 0) = y 0

y ' (t ) = 3 y + 5, y ( 0) = 1
• Example:
y ' (t ) = ty + 1, y ( 0) = 0

• Numerical methods for ordinary differential equations calculate solution on the points,
t =t +h
n n −1
where h is the steps size

4
Numerical Methods for ODE
• Euler Methods
• Euler Method
• Modified Euler Method

• Runge-Kutta Methods
• Second Order
• Third Order
• Fourth Order

5
Introduction
Initial Value Problem
Euler Method
Euler Method
• Consider the forward difference approximation for first derivative

yn +1 − yn
yn '  , h = tn +1 − t n
h
• Rewriting the above equation we have
yn +1 = yn + hyn ' , yn ' = f ( yn , t n )
• So, y n is recursively calculated as
y1 = y0 + hy0 ' = y0 + h f ( y0 , t0 )
y2 = y1 + h f ( y1 , t1 )

yn = yn −1 + h f ( yn −1 , t n −1 )
9
Euler Method
Euler Method
Euler Method
Example 1: Solve 𝑦′ = 𝑡𝑦 + 1, 𝑦0 = 𝑦(0) = 1, 0 ≤ 𝑡 ≤ 1, ℎ = 0.25

Solution:

for t0 = 0, y0 = y (0) = 1
for t1 = 0.25, y1 = y0 + hy0 '
= y0 + h(t0 y0 + 1)
= 1 + 0.25(0 *1 + 1) = 1.25
for t 2 = 0.5, y2 = y1 + hy1 '
= y1 + h(t1 y1 + 1)
etc = 1.25 + 0.25(0.25 *1.25 + 1) = 1.5781

13
Graph the solution

14
𝑑𝑦
Example 2: Solve: = 𝑥 + 𝑦, y = 0 at x = 0
𝑑𝑥
• Choose h = 0.1
• We have x0 = 0, y0 = 0, f0 = x0 + y0 = 0, x1 = x0 + h = 0.1, y1 = y0 + hf0 = 0
• Euler’s method algorithm is yi+1 = yi + hifi = yi + hi f(xi, yi)
• Next step is from x1 = 0.1 to x2 = 0.2
• f1 = x1 + y1 = 0.1 + 0 = 0.1
• y2 = y1 + hf1 = 0 + (.1)(.1) = .01
• For dy/dx = x + y, we know the exact solution is (x0 + y0 + 1)ex-x0 – x – 1
• For x0 = y0 = 0, y = ex – x – 1
• Look at application of Euler algorithm for a few steps and compute the error

15
Euler Example
xi yi fi = 𝑥 + 𝑦 y(xi)=yi + hifi E(xi)
0 0 0 0 0
.1 0 .1 .0052 .0052
.2 .01 .21 .0214 .0114
.3 .031 .331 .04986 .01886
.4 .0641 .4641 .091825 .027725
16
Euler Example Plot
0.8

0.7

0.6

0.5

0.4
y

Exact
Numerical
0.3

0.2

0.1

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
x

17
Example 3
dy/y=(𝑥 2 -1.2)dx
Example 4
Solution Analytical and Numerical
Example 5
Example 6
Comparison
Modified Euler Method
• Modified Euler method is derived by applying the trapezoidal rule to integrating
y ' = f ( y, t ) ; So, we have h
yn +1 = yn + ( yn' +1 + yn' ), yn ' = f ( yn , t n )
n

• If f is linear in y, we can solved for similar as backward euler method


• If f is nonlinear in y, we necessary to used the method for solving nonlinear
equations i.e. successive substitutionymethod (fixed point)
n +1

25
Modified Euler Method
• Better estimate for the solution than Euler method
• Average slope over the interval (t0,t1) is used instead of slope at a
point
• The solution is approximated as a straight line in the interval (t0,t1)
with slope as arithmetic average at the beginning and end point of
the interval
Modified Euler Method
Algorithm: For Numerical solution by
Modified Euler Method
Example 1
Example 1(contd.)
ℎ = 0.02

1.1−0.1)
𝑦2 = 𝑦1 + ℎ𝑓 𝑥1, 𝑦1 = 1.1 + 0.1( 1.1_0.1) =1.83
𝑑𝑦
Use Euler and Modified Euler method to solve, 𝑑𝑥
= 1 + 𝑥𝑦
with y(0)=2
𝑑𝑦
Modified Euler Method, = 1 + 𝑥𝑦 with
𝑑𝑥
y(0)=2
• Solve the IVP in the interval (0.0, 2.0) using Modified Euler method with step size
h=0.2
Example
Example
Links
• https://nptel.ac.in/courses/111/107/111107063/

You might also like