0% found this document useful (0 votes)
10 views

Numerical Solution of ODE

The document discusses numerical methods for solving ordinary differential equations, focusing on the Euler method, Modified Euler method, and Runge-Kutta method. It provides detailed examples of applying these methods to specific differential equations with step-by-step calculations. The document aims to illustrate how these numerical techniques can be used to approximate solutions over given intervals.

Uploaded by

bivaman1617
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Numerical Solution of ODE

The document discusses numerical methods for solving ordinary differential equations, focusing on the Euler method, Modified Euler method, and Runge-Kutta method. It provides detailed examples of applying these methods to specific differential equations with step-by-step calculations. The document aims to illustrate how these numerical techniques can be used to approximate solutions over given intervals.

Uploaded by

bivaman1617
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Numerical Solution of Ordinary Differential Equations

Euler Method:
dy
=f ( x , y ) , y (x ¿¿ 0)= y 0 ¿ (1)
dx
Suppose we wish to solve the eq.(1) for the values of y at
x=x n=x 0 +nh , n=1 ,2 , 3 ,. .

Integrate eq. (1) ,we have


x1

y 1= y 0 +∫ f ( x , y ) dx (2)
x0

Assuming that f ( x , y )=f (x 0 , y 0 ) in x 0 ≤ x ≤ x 1, this gives the Euler formula


y 1= y 0 + hf (x 0 , y 0 )

Similarly for the range x 1 ≤ x ≤ x 2, we have


x2

y 2= y 1 +∫ f ( x , y ) dx
x1

Substituting f (x 1 , y 1) for f ( x , y ) in x 1 ≤ x ≤ x 2, we obtain


y 2= y 1 +hf (x1 , y 1),

Proceeding in this way, we obtain the general formula


y n +1= y n + hf (x ¿ ¿ n , y n) , n=0 ,1 , 2 ,… … ¿ (3)

Example 1: Use the Euler method solve the following differential Equation
dy 2
=−2 x y , y ( 0 )=1 for h=0.2 over the interval [0,1].
dx
Solution: we have
y n +1= y n + hf (x ¿ ¿ n , y n) , n=0 ,1 , 2 ,3 , 4 ¿

With h=0.2. The initial condition gives y 0=1


For n=0 ; x 0=0 , y 0=1
y 1= y 0 + hf ( x 0 , y 0 )=1+0.2 ( −2 x 0 y 02 )=1+0.2 (−2 ×0 × 1 )=1
∴ y ( 0.2 )=1
For n=1; x 1=0.2 , y 1=1
y 2= y 1 +hf ( x 1 , y 1 ) =1+ 0.2 ( −2× 0.2× 12 )=0.92
∴ y ( 0.4 ) =0.92
For n=2; x 2=0.4 , y 2=0.92
y 3= y2 +hf ( x 2 , y 2) =0.92+0.2 ¿
∴ y ( 0.6 )=0.78458
For n=3 ; x3 =0.6 , y 3=0.78458
y 4 = y 3 +hf ( x 3 , y 3 ) =0.78458+0.2 ¿
∴ y ( 0.8 )=0.63648
For n=4 ; x 4 =0.8 , y 4 =0.63648
y 5= y 4 +hf ( x 4 , y 4 ) =0.63648+0.2 ¿
∴ y (1.0 )=0.50706

Example 2: Use the Euler method solve the following differential Equation
dy
=2 y /x , y (1 )=2 for h=0.25 over the interval [0,1].
dx
Solution: We have
y n +1= y n + hf (x ¿ ¿ n , y n), n=0 ,1 , 2 ,3 , 4 ¿…….

For n=0 ; x 0=1 , y 0=2, h=0.25.


y 1= y 0 + hf ( x 0 , y 0 )=2+ 0.25 ( 2 y 0 /x 0 ) =2+ 0.25 ( 2× 2/1 )=3
∴ y (1.25 )=3
For n=1; x 1=1.25 , y 1=3, h=0.25.
y 2= y 1 +hf ( x 1 , y 1 ) =3+0.25 ( 2 ×3/1.25 ) =4.2
∴ y (1.5 )=4.2

For n=2; x 2=1.5 , y 2=4.2, h=0.25.


y 3= y2 +hf ( x 2 , y 2) =4.2+ 0.25 ( 2 × 4.2/1.5 )=5.6
∴ y (1.75 )=5.6

For n=3 ; x3 =1.75 , y 3 =5.6, h=0.25.


y 4 = y 3 +hf ( x 3 , y 3 ) =5.6+0.25 ( 2 ×5.6 /1.75 )=7.2
∴ y ( 2. )=7.2
Modified Euler’s Method:
Instead of approximation f (x , y ) by f (x 0 , y 0 ) in the eq. (2), we now approximate the
integral given in eq. (2) by means of trapezoidal rule to obtain
h
y 1= y 0 + [f ( x 0 , y 0 )+ f ( x 1 , y 1 ) ] (4)
2
we thus obtain the iteration formula
h
= y 0+ [f ( x 0 , y 0 ) +f ( x 1 , y 1 ) ],n=0 , 1 ,2 , … … (5)
(n +1) (n)
y1
2

Where y (n1 ) is the nth approximation to y 1. The iteration formula (5) can be started
by choosing y (01 ) from Euler’s formula.

Example 2: Use the Modified Euler method solve the following differential
dy
Equation dx =2 y /x , y (1 )=2 for h=0.25 over the interval [0,1].

Solution: We have
h
= y 0+ [f ( x 0 , y 0 ) +f ( x 1 , y 1 ) ],n=0 , 1 ,2 , … …
(n +1) (n)
y1
2

We take x 0=1 , y 0=2, h=0.25, we have f ( x 0 , y 0 )=4


Hence Euler formula gives
2
y 1 = y 0 +h [ f ( x 0 , y 0 ) ]= y 0 +h ( 2 y 0 / x 0 )=2+0.25 (2× )=3
(0 )
1
3
Further x 1=1.25 , and f ( x 1 , y 1 )=2 × 1.25 =4.8
(0 )

h 0.25
Therefore y 1 = y 0 + 2 [ f ( x 0 , y 0 ) + f ( x 1 , y 1 ) ]=2+ 2 [ 4+ 4.8 ] =3.1
(1 ) ( 0)

3.1
Now, f ( x 1 , y 1 ) =2 × 1.25 =4.96
(1 )

h 0.25
Therefore y 1 = y 0 + 2 [ f ( x 0 , y 0 ) + f ( x 1 , y 1 ) ] =2+ 2 [ 4 +4.96 ] =3.12
(2 ) ( 1)

3.12
Now, f ( x 1 , y 1 ) =2 × 1.25 =4.992
(2 )

h 0.25
Therefore y 1 = y 0 + 2 [ f ( x 0 , y 0 )+ f ( x 1 , y 1 ) ]=2+ 2 [ 4+ 4.992 ]
(3 ) ( 2)

¿ 3.124
∴ y (1.25 )=3.12
Here x 1=1.25 , y 1=3.12 , f ( x 1 , y 1) =4.992
y 2 = y 1 +h [ f ( x 1 , y 1) ]=3.12+0.25 × 4.992=4.368
(0 )

4.368
Further x 2=1.5 , and f ( x 2 , y 2 )=2 × 1.5 =5.824
(0 )

h 0.25
Now y 2 = y 1 + 2 [ f ( x 1 , y 1 ) +f ( x2 , y 2 ) ] =3.12+ 2 [ 4.992+5.824 ]
(1 ) (0 )

¿ 4.472
4.472
Now, f ( x 2 , y 2 ) =2 × 1.5 =5.9627
(1 )

h 0.25
Therefore y 2 = y 1 + 2 [ f ( x1 , y 1 ) +f ( x 2 , y 2 ) ]=3.12+ 2 [ 4.992+ 5.9627 ] =4.4893
(2 ) ( 1)

4.4893
Now, f ( x 2 , y 2 ) =2 × 1.5 =5.9857
(2 )

h 0.25
Therefore y 2 = y 1 + 2 [ f ( x 1 , y 1 ) +f ( x2 , y 2 ) ]=3.12+ 2 [ 4.992+5.9857 ] =4.4922
(3 ) (2 )

∴ y (1.5 )=4.49

Here x 2=1.5 , y 2=4.49 , f ( x 2 , y 2 )=5.9867


y 3 = y 2 +h [ f ( x 2 , y 2 ) ]=4.49+0.25 ×5.9867=5.9867
(0 )

5.9867
Further x 3=1.75 , and f ( x 3 , y 3 )=2 × 1.75 =6.8419
(0 )

h 0.25
therefore y 3 = y 2 + 2 [ f ( x 2 , y 2 ) +f ( x3 , y 3 ) ] =4.49+ 2 [ 5.9867+ 6.8419 ] =6.0936
(1 ) (0 )

6.0936
Now, f ( x 3 , y 3 ) =2 × 1.75 =6.9641
(1 )

h 0.25
(2 )
y3 = y2+
2
[ ]
f ( x 2 , y 2 ) + f ( x3 , y (31 )) =4.49+
2
[ 5.9867+6.9641 ] =6.1089

6.1089
Now, f ( x 3 , y 3 ) =2 × 1.75 =6.9816
(2 )

h 0.25
(3 )
y3 = y2+
2
[ ]
f ( x 2 , y 2 ) + f ( x 3 , y (32 )) =4.49+
2
[ 5.9867+ 6.9816 ] =6.1110

∴ y (1.75 )=6.11

Here x 3=1.75 , y 3=6.11 , f ( x 3 , y 3 )=6.9829


y 4 = y 3 +h [ f ( x3 , y 3 ) ]=6.11+0.25 ×6.9829=7.8557
(0 )

7.8557
Further x 4 =2.0 , and f ( x 4 , y 4 ) =2 × 2.0 =7.8557
( 0)

h 0.25
therefore y 4 = y 3 + 2 [ f ( x 3 , y 3 ) + f ( x 4 , y 4 ) ]=6.11+ 2 [ 6.9829+7.8557 ] =7.9648
(1 ) (0 )

7.9648
Now, f ( x 4 , y 4 ) =2× 2.0 =7.9648
( 1)

h 0.25
(2 )
y4 = y3+
2
[ ]
f ( x 3 , y 3 ) + f ( x 4 , y (41) ) =6.11+
2
[ 6.9829+7.9648 ] =7.9785

7.9785
Now, f ( x 4 , y 4 ) =2× 2.0 =7.9785
( 2)

h 0.25
(3 )
y4 = y3+
2
[ ]
f ( x 3 , y 3 ) + f ( x 4 , y (42) ) =6.11+
2
[ 6.9829+7.9785 ] =7.9802

∴ y ( 2.0 )=7.98

Runge-Kutta Method:
Example 2: Use the Runge-Kutta second order (RK-2) method solve the
dy
following differential Equation dx =2 y /x , y (1 )=2 for h=0.25 over the interval [1,2].

Solution: We have RK-2 method


y i+ 1= y i+ [ k 1 +k 2 ) ¿ /2 , i=0 , 1 ,2 , … …

k 1=h∗f ( x i , y i )
k 2=h∗f ( x i+ h , y i+ k 1 )

For i=0 ; x 0=1 , y 0=2, h=0.25, we have

k 1=h × f ( x 0 , y 0 )=0.25× 2 × ( 21 )=1


k 2=0.25 × f ( x 0 +h , y 0 + k 1 )=0.25 × f ( 1.25 ,3 )=0.25 × 4.8=1.2
1
y 1= y 0 + [ k + k ) ¿=2+ 0.5 ( 1+1.2 ) =2+1.1=3.1
2 1 2
y ( 1.25 )=3.1

For i=1 ; x 1=1.25 , y 1 =3.1, h=0.25, we have

k 1=h × f ( x 1 , y 1) =0.25 × 2 × ( )
3.1
1.25
=1.24
k 2=0.25 × f ( x 1 +h , y 1 +k 1 ) =0.25 × f ( 1.5 , 4.34 )=1.4467
1
y 2= y 1 + [ k + k ) ¿=3.1+0.5 ( 1.24+ 1.4467 )=4.4433
2 1 2
y (1.5)=4.4433

For i=2 ; x 2=1.5 , y 2=4.4433 , h=0.25, we have

(
k 1=h × f ( x 2 , y 2 )=0.25 × 2 ×
4.4433
1.5 )
=1.4811

k 2=0.25 × f ( x 2 +h , y 2 +k 1 ) =0.25 × f ( 1.75 , 5.9244 )=1.6927


1
y 3= y2 + [ k + k ) ¿=4.4433+0.5 ( 1.4811+1.6927 )=6.0302
2 1 2
y (1.75)=6.0302

For i=3 ; x 3=1.75 , y 3=6.0302 , h=0.25 , we have

(
k 1=h × f ( x 3 , y 3 )=0.25 × 2 ×
6.0302
1.75 )
=1.7229

k 2=0.25 × f ( x 3 +h , y 3 +k 1 ) =0.25 × f ( 2.0 ,7.7531 )=1.9383


1
y4= y3+ [ k +k ) ¿=6.0302+0.5 ( 1.7229+1.9383 ) =7.8608
2 1 2
y (2)=7.8608

Example 2: Use the Mid Point method solve the following differential Equation
dy
=2 y /x , y (1 )=2 for h=0.25 over the interval [0,1].
dx
Solution: We have Mid-Point method
y i+ 1= y i+ k 2 ,i=0 ,1 , 2 , … …

k 1=h∗f ( x i , y i )
k 2=h∗f ( x i+ h/2 , y i+ k 1 /2 )

For i=0 ; x 0=1 , y 0=2, h=0.25, we have

( 21 )=1
k 1=h × f ( x 0 , y 0 )=0.25× 2 ×

k 2=0.25 × f ( x 0 +h /2 , y 0 + k 1 /2 )=0.25 × f ( 1.125 ,2.5 )=1.1111


y 1= y 0 + k 2=2+1.1111=3.1111

y ( 1.25 )=3.1111

For i=1 ; x 1=1.25 , y 1 =3.1111,h=0.25, we have

(
k 1=h × f ( x 1 , y 1) =0.25 × 2 ×
3.1111
1.25 )
=1.2444

k 2=0.25 × f ( x 1 +h /2 , y 1 +k 1 /2 ) =0.25 × f ( 1.375 , 3.7333 )=1.3576


y 2= y 1 +k 2=3.1111+1.3576=4.4687

y ( 1.5 )=4.4687

For i=2 ; x 2=1.5 , y 2=4.4687 , h=0.25, we have

(
k 1=h × f ( x 2 , y 2 )=0.25 × 2 ×
4.4687
1.5 )
=1.4896

k 2=0.25 × f ( x 2 +h /2 , y 2 +k 1 /2 ) =0.25 × f ( 1.625 , 5.2135 )=1.6042


y 3= y2 + k 2=4.4686 +1.6042=6.0728

y ( 1.75 )=6.0728

For i=3 ; x 3=1.75 , y 3=6.0728 , h=0.25, we have

(
k 1=h × f ( x 3 , y 3 )=0.25 × 2 ×
6.0728
1.75 )
=1.7351

k 2=0.25 × f ( x 3 +h /2, y 3 +k 1 /2 ) =0.25 × f (1.875 , 6.9404 )=1.8508


y 4 = y 3 +k 2=6.0302+ 1.8508=7.9236

y ( 2.0 )=7.9236

Example 2: Use the RK-4 method solve the following differential Equation
dy
=2 y /x , y (1 )=2 for h=0.25 over the interval [0,1].
dx
Solution: We have RK-4 method
y i+ 1= y i+ [ k 1 +2 k 2 +2 k 3 +k 4 ) ¿/6 , i=0 , 1 ,2 , … …

k 1=h∗f ( x i , y i )
k 2=h∗f ( x i+ h/2 , y i+ k 1 /2 )
k 3=h∗f ( x i +h/2 , y i+ k 2 /2 )
k 4=h∗f ( xi +h , y i +k 3 )

For i=0 ; x 0=1 , y 0=2, h=0.25, we have

k 1=h∗f ( x 0 , y 0 ) =0.25 × f ( 1, 2 )=0.25× 2 × ( 21 )=1


k 2=h∗f ( x 0 +h/2 , y 0 +k 1 /2 ) =0.25 ×f ( 1.125 , 2.5 )=1.1111
k 3=h∗f ( x 0 +h/2 , y 0 +k 2 /2 ) =0.25 × f ( 1.125 , 2.5556 )=1.1358
k 4=h∗f ( x0 + h , y 0 + k 3 )=0.25 × f ( 1.25 , 3.1358 )=1.2543
1 1+2 ×1.1111+2 ×1.1358+1.2543
y 1= y 0 +
6
[ k 1 +2 k 2 +2 k 3 +k 4 ) ¿=2+
6
=3.1247

y ( 1.25 )=3.1247

For i=1 ; x 1=1.25 , y 1 =3.1247, h=0.25, we have

k 1=h∗f ( x 1 , y 1 )=0.25× f ( 1.25 , 3.1247 )=0.25× 2× ( 3.1247


1.25 )
=1.2499

k 2=h∗f ( x 1+ h/2 , y1 + k 1 /2 )=0.25 × f ( 1.375 ,3.7497 )=1.3635


k 3=h∗f ( x 1+ h/2 , y 1+ k 2 /2 )=0.25 × f ( 1.375 , 3.8065 )=1.3842
k 4=h∗f ( x1 +h , y 1 +k 3 ) =0.25 × f (1.5 , 4.5089 )=1.5030
1 1.2499+2 ×1.3635+2 ×1.3842+1.5030
y 2= y 1 +
6
[ k 1+ 2 k 2+ 2 k 3+ k 4 ) ¿=3.1247+
6
=4.4994

y ( 1.5 )=4.4994

For i=2 ; x 2=1.5 , y 2=4.4994 , h=0.25, we have

k 1=h∗f ( x 2 , y 2 )=0.25× f ( 1.5 , 4.4994 )=0.25 × 2 × ( 4.4994


1.5 )=1.4998

k 2=h∗f ( x 2+ h/2 , y 2+ k 1 /2 )=0.25 × f ( 1.625 ,5.2493 )=1.6152


k 3=h∗f ( x 2 +h/2 , y 2+ k 2 /2 )=0.25 × f ( 1.625 , 5.3070 )=1.6329
k 4=h∗f ( x2 +h , y 2 +k 3 ) =0.25 × f (1.75 ,6.1323 )=1.7521
1 1.4998+2 ×1.6151+2 ×1.6329+1.7521
y 3= y2 +
6
[ k 1 +2 k 2 +2 k 3 +k 4 ) ¿=4.4994+
6
=6.1240

y ( 1.75 )=6.1240
For i=3 ; x 3=1.75 , y 3=6.1240, h=0.25, we have

(
k 1=h∗f ( x 3 , y 3 ) =0.25 × f ( 1.75 , 6.1240 ) =0.25 × 2×
6.1240
1.75 )=1.7497

k 2=h∗f ( x 3 +h/2 , y 3+ k 1 /2 )=0.25× f ( 1.875 , 6.9989 )=1.8664


k 3=h∗f ( x 3 +h/2 , y 3+ k 2 /2 )=0.25× f ( 1.875 , 7.0572 )=1.8819
k 4=h∗f ( x3 +h , y 3 +k 3 )=0.25 × f ( 2.0 , 8.0059 )=2.0015
1 1.7497+2 ×1.8664+ 2× 1.8819+2.0015
y4= y3+
6
[ k 1+2 k 2+2 k 3 + k 4 ) ¿=6.1240+
6
=7.9986

y ( 2.0 )=7.9986
Table 1: Example of 2 by different methods.
x Euler Modified Euler RK-2 Mid Point RK-4 Exact y=2 x 2
x=1.25 3.0 3.12 3.10 3.1111 3.1247 3.125
x=1.50 4.2 4.49 4.4433 4.4687 4.4994 4.50
x=1.75 5.6 6.11 6.0302 6.0728 6.1240 6.125
x=2.00 7.2 7.98 7.8608 7.9236 7.9986 8.00

You might also like