0% found this document useful (0 votes)
193 views12 pages

Improved Euler Method & Modified Euler Method (Second Order Runge Kutta Method) Requirements: Geometrical Interpretation of Derivative

Improved Euler Method & Modified Euler Method (Second Order Runge Kutta Method)

Uploaded by

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

Improved Euler Method & Modified Euler Method (Second Order Runge Kutta Method) Requirements: Geometrical Interpretation of Derivative

Improved Euler Method & Modified Euler Method (Second Order Runge Kutta Method)

Uploaded by

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

MA401 – NMCP : Improved Euler Method

Improved Euler Method & Modified Euler Method (Second Order Runge Kutta Method)

Requirements: Geometrical Interpretation of derivative

(i) This method is a self-starting method of predictor corrector type having greater accuracy
than Euler method.
(ii) It is known by a variety of names such as Euler Trapezoidal method, Euler Predictor-
Corrector method, the Improved Euler Method, Heun’s method, Euler-Cauchy method and
Modified Euler method.
𝑑𝑦
Consider the first order differential equation 𝑑𝑥 = 𝑓(𝑥, 𝑦) with initial condition 𝑦 = 𝑦0 when 𝑥 = 𝑥0

To find the value of 𝑦 at 𝑥 = 𝑥𝑛+1 , Improved Euler Method makes use of average slope of 𝑦𝑛′ (i.e.
′ ′ ℎ
𝑓(𝑥𝑛 , 𝑦𝑛 )) and 𝑦𝑛+1 (i.e. 𝑓(𝑥𝑛+1 , 𝑦𝑛+1 )) as 𝑦𝑛+1 = 𝑦𝑛 + 2 {𝑦𝑛′ + 𝑦𝑛+1 }

or 𝑦𝑛+1 = 𝑦𝑛 + {𝑓(𝑥𝑛 , 𝑦𝑛 ) + 𝑓(𝑥𝑛+1 , 𝑦𝑛+1 )}
2

Let us consider a line passing through (𝑥0 , 𝑦0 ) whose slope is the average of the slopes at (𝑥0 , 𝑦0 ) and
(1)
(𝑥1 , 𝑦1 ).

(1) (1)
Here 𝑦1 is known as the first approximation of 𝑦1 and is obtained by Euler method as 𝑦1 = 𝑦0 +
ℎ𝑓(𝑥0 , 𝑦0 )

The equation of the line passing through (𝑥0 , 𝑦0 ) and having slope which is the average of the slopes at
(1)
(1) 𝑓(𝑥0 ,𝑦0 )+𝑓((𝑥1 ,𝑦1 )
(𝑥0 , 𝑦0 ) and (𝑥1 , 𝑦1 ) is 𝑦 − 𝑦0 = (𝑥 − 𝑥0 ) { }
2

(1)
𝑓(𝑥0 ,𝑦0 )+𝑓((𝑥1 ,𝑦1 )
Since this line is to pass through (𝑥1 , 𝑦1 ) we get 𝑦1 − 𝑦0 = (𝑥1 − 𝑥0 ) { 2
}

(1)
𝑓(𝑥0 , 𝑦0 ) + 𝑓((𝑥1 , 𝑦1 )
𝑦1 = 𝑦0 + ℎ { }
2

In general,
(1)
𝑓(𝑥𝑛 ,𝑦𝑛 )+𝑓((𝑥𝑛+1 , 𝑦𝑛+1 ) (1)
𝑦𝑛+1 = 𝑦𝑛 + ℎ { 2
}, where 𝑦𝑛+1 = 𝑦𝑛 + ℎ𝑓(𝑥𝑛 , 𝑦𝑛 )

This is known as Improved Euler formula.

To obtain 𝑦2 , it would be

(1)
𝑦2 = 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 )

(1)
𝑓(𝑥1 , 𝑦1 ) + 𝑓((𝑥2 , 𝑦2 )
𝑦2 = 𝑦1 + ℎ { }
2

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 1 of 12


MA401 – NMCP : Improved Euler Method

To obtain 𝑦3 , it would be

(1)
𝑦3 = 𝑦2 + ℎ𝑓(𝑥2 , 𝑦2 )

(1)
𝑓(𝑥2 , 𝑦2 ) + 𝑓((𝑥3 , 𝑦3 )
𝑦3 = 𝑦2 + ℎ { }
2

To obtain 𝑦4 , it would be

(1)
𝑦4 = 𝑦3 + ℎ𝑓(𝑥3 , 𝑦3 )

(1)
𝑓(𝑥3 , 𝑦3 ) + 𝑓((𝑥4 , 𝑦4 )
𝑦4 = 𝑦3 + ℎ { }
2

and so on …

Pseudo Code for Improved Euler Method:

(1) Read 𝑥0 , 𝑦0 , ℎ, 𝑥𝑛 where 𝑥0 , 𝑦0 are the initial values, ℎ is the step length, 𝑥𝑛 is value of x
for which y is required
(2) While 𝑥0 ≤ 𝑥𝑛
(3) Print 𝑥0 , 𝑦0
(4) 𝑥1 ← 𝑥0 + ℎ
(5) 𝑡1 ← 𝑓(𝑥0 , 𝑦0 )
(6) 𝑡𝑦 ← 𝑦0 + ℎ × 𝑡1
(7) 𝑡2 ← 𝑓(𝑥1 , 𝑡𝑦)
(8) 𝑦1 ← 𝑦0 + ℎ × (𝑡1 + 𝑡2)/2
(9) 𝑦0 ← 𝑦1
(10) 𝑥0 ← 𝑥1
(11) End while
(12) stop

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 2 of 12


MA401 – NMCP : Improved Euler Method

Modified Euler Method:

The first approximation for 𝑦1 at 𝑥 = 𝑥1 obtained as 𝑦1 = 𝑦0 + ℎ𝑓(𝑥0 , 𝑦0 ) may be improved by taking a


second approximation as
(1)
(2) 𝑓(𝑥0 , 𝑦0 ) + 𝑓((𝑥1 , 𝑦1 )
𝑦1 = 𝑦0 + ℎ { }
2

The third approximation for 𝑦1 being


(2)
(3) 𝑓(𝑥0 , 𝑦0 ) + 𝑓((𝑥1 , 𝑦1 )
𝑦1 = 𝑦0 + ℎ { }
2

In general, the nth approximation for 𝑦1 being


(𝑛−1)
(𝑛) 𝑓(𝑥0 , 𝑦0 ) + 𝑓((𝑥1 , 𝑦1 )
𝑦1 = 𝑦0 + ℎ { }
2

To obtain 𝑦2 , it would be

(1)
𝑦2 = 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 )

(1)
(2) 𝑓(𝑥1 , 𝑦1 ) + 𝑓((𝑥2 , 𝑦2 )
𝑦2 = 𝑦1 + ℎ { }
2

(2)
(3) 𝑓(𝑥1 , 𝑦1 ) + 𝑓((𝑥2 , 𝑦2 )
𝑦2 = 𝑦1 + ℎ { }
2

(3)
(4) 𝑓(𝑥1 ,𝑦1 )+𝑓((𝑥2 ,𝑦2 )
𝑦2 = 𝑦1 + ℎ { 2
}, etc…

To obtain 𝑦3 , it would be

(1)
𝑦3 = 𝑦2 + ℎ𝑓(𝑥2 , 𝑦2 )

(1)
(2) 𝑓(𝑥2 , 𝑦2 ) + 𝑓((𝑥3 , 𝑦3 )
𝑦3 = 𝑦2 + ℎ { }
2

(2)
(3) 𝑓(𝑥2 , 𝑦2 ) + 𝑓((𝑥3 , 𝑦3 )
𝑦3 = 𝑦2 + ℎ { }
2

(3)
(4) 𝑓(𝑥2 ,𝑦2 )+𝑓((𝑥3 ,𝑦3 )
𝑦3 = 𝑦2 + ℎ { 2
}, etc…

and so on …

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 3 of 12


MA401 – NMCP : Improved Euler Method

Remarks:

The first approximations to 𝑦2 , 𝑦3 , … … ..etc could be found by means of Euler formula as


𝑦𝑛+1 = 𝑦𝑛 + ℎ𝑓(𝑥𝑛 , 𝑦𝑛 )

But as soon as two consecutive values of 𝑦 are known (i.e. from 𝑦2 onwards), the first approximation to
succeeding 𝑦’s can be obtained more accurately by the formula 𝑦𝑛+1 = 𝑦𝑛−1 + 2ℎ𝑓(𝑥𝑛 , 𝑦𝑛 ).

That is, from 𝑦2 onwards we may use

To obtain 𝑦2 , it would be

(1)
𝑦2 = 𝑦0 + 2ℎ𝑓(𝑥1 , 𝑦1 )

(1)
(2) 𝑓(𝑥1 , 𝑦1 ) + 𝑓((𝑥2 , 𝑦2 )
𝑦2 = 𝑦1 + ℎ { }
2

(2)
(3) 𝑓(𝑥1 , 𝑦1 ) + 𝑓((𝑥2 , 𝑦2 )
𝑦2 = 𝑦1 + ℎ { }
2

(3)
(4) 𝑓(𝑥1 ,𝑦1 )+𝑓((𝑥2 ,𝑦2 )
𝑦2 = 𝑦1 + ℎ { 2
}, etc…

To obtain 𝑦3 , it would be

(1)
𝑦3 = 𝑦1 + 2ℎ𝑓(𝑥2 , 𝑦2 )

(1)
(2) 𝑓(𝑥2 , 𝑦2 ) + 𝑓((𝑥3 , 𝑦3 )
𝑦3 = 𝑦2 + ℎ { }
2

(2)
(3) 𝑓(𝑥2 , 𝑦2 ) + 𝑓((𝑥3 , 𝑦3 )
𝑦3 = 𝑦2 + ℎ { }
2

(3)
(4) 𝑓(𝑥2 ,𝑦2 )+𝑓((𝑥3 ,𝑦3 )
𝑦3 = 𝑦2 + ℎ { 2
}, etc…

and so on …

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 4 of 12


MA401 – NMCP : Improved Euler Method

Pseudo Code for Modified Euler Method:

(1) Read 𝑥0 , 𝑦0 , ℎ, 𝑥𝑛, 𝜖 where 𝑥0 , 𝑦0 are the initial values, ℎ is the step length, 𝑥𝑛 is value of 𝑥
for which 𝑦 is required and 𝜖 is the precision value
(2) While (𝑥0 ≤ 𝑥𝑛 )
(3) Print 𝑥0 , 𝑦0
(4) 𝑡1 ← 𝑓(𝑥0 , 𝑦0 )
(5) 𝑦11 ← 𝑦0 + ℎ × 𝑡1
(6) 𝑥1 ← 𝑥0 + ℎ
(7) 𝑡2 ← 𝑓(𝑥1 , 𝑦11 )
(8) 𝑦12 ← 𝑦0 + ℎ × (𝑡1 + 𝑡2)/2
(9) While (𝑦11 − 𝑦12 ) > 𝜖
(10) 𝑡3 ← 𝑓(𝑥1 , 𝑦12 )
(11) 𝑦13 ← 𝑦0 + ℎ × (𝑡1 + 𝑡3)/2
(12) 𝑦11 ← 𝑦12
(13) 𝑦12 ← 𝑦13
(14) End while
(15) 𝑥0 ← 𝑥1
(16) 𝑦0 ← 𝑦12
(17) End while
(18) stop

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 5 of 12


MA401 – NMCP : Improved Euler Method

Example No. 1 (Improved Euler Method):


𝑑𝑦
Solve numerically 𝑑𝑥
= 𝑦 + 𝑒 𝑥 , 𝑦(0) = 0 for 𝑥 = 0.2, 0.4 by Improved Euler Method

Soln: Here we are given


𝑑𝑦
𝑑𝑥
= 𝑓(𝑥, 𝑦) = 𝑦 + 𝑒 𝑥 , with 𝑥0 = 0, 𝑦0 = 0,

Also, 𝑥1 = 0.2, 𝑥2 = 0.4, so ℎ = 𝑥1 − 𝑥0 = 0.2 − 0 = 0.2

Using Improved Euler Method,

(1)
𝑦1 = 𝑦0 + ℎ𝑓(𝑥0 , 𝑦0 ) = 𝑦0 + ℎ{𝑦0 + 𝑒 𝑥0 } = 0 + 0.2{0 + 𝑒 0 } = 0.2

ℎ (1) ℎ (1)
𝑦1 = 𝑦0 + {𝑓(𝑥0 , 𝑦0 ) + 𝑓(𝑥1 , 𝑦1 )} = 𝑦0 + [{𝑦0 + 𝑒 𝑥0 } + {𝑦1 + 𝑒 𝑥1 }]
2 2
0.2
=0+ 2
[{0 + 𝑒 0 } + {0.2 + 𝑒 0.2 }] =0.24214

(1)
𝑦2 = 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 ) = 0.24214 + 0.2{0.24214 + 𝑒 0.2 } = 0.53485

(1)
𝑓(𝑥1 , 𝑦1 ) + 𝑓((𝑥2 , 𝑦2 ) {0.24214 + 𝑒 0.2 } + {0.53485 + 𝑒 0.4 }
𝑦2 = 𝑦1 + ℎ { } = 0.24214 + 0.2 [ ]
2 2
= 0.59116

Example No. 2 (Improved Euler Method):


𝑑𝑦 2𝑥
Using Improved Euler method find 𝑦 at 𝑥 = 0.1 and 𝑥 = 0.2 given that 𝑑𝑥 = 𝑦 − 𝑦
, y(0) = 1
[2012, 2013]

Soln: Here we are given


𝑑𝑦 2𝑥
𝑑𝑥
= 𝑓(𝑥, 𝑦) = 𝑦 − 𝑦
, with 𝑥0 = 0, 𝑦0 = 1,

Also, 𝑥1 = 0.1, 𝑥2 = 0.2, so ℎ = 𝑥1 − 𝑥0 = 0.1 − 0 = 0.1

Using Improved Euler Method,

(1) 2𝑥0 2(0)


𝑦1 = 𝑦0 + ℎ𝑓(𝑥0 , 𝑦0 ) = 𝑦0 + ℎ {𝑦0 − } = 1 + 0.1 {1 − } = 1.1
𝑦0 1

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 6 of 12


MA401 – NMCP : Improved Euler Method

ℎ (1) ℎ 2𝑥0 (1) 2𝑥1


𝑦1 = 𝑦0 + {𝑓(𝑥0 , 𝑦0 ) + 𝑓(𝑥1 , 𝑦1 )} = 𝑦0 + [{𝑦0 − } + {𝑦1 − (1) }]
2 2 𝑦0 𝑦 1

0.1 2(0) 2(0.1)


=1+ [{1 − } + {1.1 − }] = 1.095909
2 1 1.1

Now,

(1) 2(0.1)
𝑦2 = 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 ) = 1.095909 + 0.1 {1.095909 − } = 1.18725
1.095909
ℎ (1)
𝑦2 = 𝑦1 + {𝑓(𝑥1 , 𝑦1 ) + 𝑓(𝑥2 , 𝑦2 )}
2
0.1 2(0.1) 2(0.2)
= 1.095909 + [{1.095909 − } + {1.18725 − }] = 1.1841009
2 1.095909 1.18725

Example No. 3 (Modified Euler Method):


𝑑𝑦
Given that = 𝑥 + 𝑦 with the initial condition that 𝑦 = 1 when 𝑥 = 0. Find 𝑦 for 𝑥 = 0.05 𝑎𝑛𝑑 𝑥 =
𝑑𝑥
0.1. Give the correct result upto four places of decimals. (Modified Euler Method)

Soln:
𝑑𝑦
Given that 𝑓(𝑥, 𝑦) = = 𝑥 + 𝑦 with 𝑥0 = 0, 𝑦0 = 1.
𝑑𝑥

Also 𝑥1 = 0.05, 𝑥2 = 0.1, so ℎ = 𝑥1 − 𝑥0 = 0.05 − 0 = 0.05

Finding 𝒚𝟏 :

(1)
𝑦1 = 𝑦0 + ℎ𝑓(𝑥0 , 𝑦0 ) = 𝑦0 + ℎ{𝑥0 + 𝑦0 } = 1 + 0.05{0 + 1} = 1.05

(2) ℎ (1) ℎ (1)


𝑦1 = 𝑦0 + {𝑓(𝑥0 , 𝑦0 ) + 𝑓(𝑥1 , 𝑦1 )} = 𝑦0 + [{𝑥0 + 𝑦0 } + {𝑥1 + 𝑦1 }]
2 2
0.05
=1+ [{0 + 1} + {0.05 + 1.05}] = 1.0525
2

(3) ℎ (2) ℎ (2)


𝑦1 = 𝑦0 + {𝑓(𝑥0 , 𝑦0 ) + 𝑓(𝑥1 , 𝑦1 )} = 𝑦0 + [{𝑥0 + 𝑦0 } + {𝑥1 + 𝑦1 }]
2 2
0.05
=1+ [{0 + 1} + {0.05 + 1.0525}] = 1.05256
2

(4) ℎ (3) ℎ (3)


𝑦1 = 𝑦0 + {𝑓(𝑥0 , 𝑦0 ) + 𝑓(𝑥1 , 𝑦1 )} = 𝑦0 + [{𝑥0 + 𝑦0 } + {𝑥1 + 𝑦1 }]
2 2

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 7 of 12


MA401 – NMCP : Improved Euler Method

0.05
=1+ [{0 + 1} + {0.05 + 1.05256}] = 1.05256
2
(3) (4)
Since 𝑦1 = 𝑦1 , we stop here and take 𝑦1 = 1.05256

Finding 𝒚𝟐 :

(1)
𝑦2 = 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 ) = 𝑦1 + ℎ{𝑥1 + 𝑦1 } = 1.05256 + 0.05{0.05 + 1.05256} = 1.107688

(2) ℎ (1) ℎ (1)


𝑦2 = 𝑦1 + {𝑓(𝑥1 , 𝑦1 ) + 𝑓(𝑥2 , 𝑦2 )} = 𝑦1 + [{𝑥1 + 𝑦1 } + {𝑥2 + 𝑦2 }]
2 2
0.05
= 1.05256 + [{0.05 + 1.05256} + {0.1 + 1.107688}] = 1.1103162
2

(3) ℎ (2) ℎ (2)


𝑦2 = 𝑦1 + {𝑓(𝑥1 , 𝑦1 ) + 𝑓(𝑥2 , 𝑦2 )} = 𝑦1 + [{𝑥1 + 𝑦1 } + {𝑥2 + 𝑦2 }]
2 2
0.05
= 1.05256 + [{0.05 + 1.05256} + {0.1 + 1.1103162}] = 1.110381905
2
(2) (3)
Since 𝑦2 = 𝑦2 upto four places of decimals, we take 𝑦2 = 1.1103

Alternative & Better Way of Finding 𝒚𝟐 and subsequent values of 𝒚

(1)
𝑦2 = 𝑦0 + 2ℎ𝑓(𝑥1 , 𝑦1 ) = 𝑦0 + 2ℎ{𝑥1 + 𝑦1 } = 1 + 2(0.05){0.05 + 1.05256} = 1.110256

Please note how we find the first approximation


as given in the theory, the other steps remain
the same as above

(2) ℎ (1) ℎ (1)


𝑦2 = 𝑦1 + {𝑓(𝑥1 , 𝑦1 ) + 𝑓(𝑥2 , 𝑦2 )} = 𝑦1 + [{𝑥1 + 𝑦1 } + {𝑥2 + 𝑦2 }]
2 2
0.05
= 1.05256 + [{0.05 + 1.05256} + {0.1 + 1.110256}] = 1.1103804
2

(3) ℎ (2) ℎ (2)


𝑦2 = 𝑦1 + {𝑓(𝑥1 , 𝑦1 ) + 𝑓(𝑥2 , 𝑦2 )} = 𝑦1 + [{𝑥1 + 𝑦1 } + {𝑥2 + 𝑦2 }]
2 2
0.05
= 1.05256 + [{0.05 + 1.05256} + {0.1 + 1.1103804}] = 1.11038351
2
(2) (3)
Since 𝑦2 = 𝑦2 upto four places of decimals, we take 𝑦2 = 1.1103.

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 8 of 12


MA401 – NMCP : Improved Euler Method

Assignment 2: (Submission Date – 25th May 2021)


𝑑𝑦 2𝑦
(1) Using modified Euler’s method, find 𝑦 at 𝑥 = 1.2 and 𝑥 = 1.4 given that 𝑑𝑥 = 𝑥
+ 𝑥 3 ; 𝑦(1) =
0.5 [2014]
𝑑𝑦
(2) Using Euler’s modified method, find a solution of the equation 𝑑𝑥
= 𝑥 + |√𝑦| with initial
condition 𝑦 = 1 at 𝑥 = 0 for the range 0 ≤ 𝑥 ≤ 0.6 in steps of 0.2

Instructions: Submit on or before 25th May 2021 online (Google Form) in


a single PDF file through the link :

https://docs.google.com/forms/d/e/1FAIpQLSfA0MThqqiO1UUYPLOmo
ggSAvaJ_OW0xjCSyoDL3TiFCXvRag/viewform?usp=sf_link

neatly self handwritten and scanned.

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 9 of 12


MA401 – NMCP : Improved Euler Method

Practice Questions:

Solve by Improved Euler Method

𝑑𝑦 2𝑥
(1) Given = 𝑦− , 𝑦(0) = 1, ℎ = 0.1. Find 𝑦(0.3)
𝑑𝑥 𝑦
𝑑𝑦
(2) Given = 𝑥 + 𝑦, 𝑦(0) = 0, ℎ = 0.2. Find 𝑦(0.6), 𝑦(0.8), 𝑦(1)
𝑑𝑥
𝑑𝑦
(3) Calculate 𝑦(0.5) taking ℎ = 0.1 and = 𝑦 + 𝑆𝑖𝑛 𝑥, 𝑦(0) = 2
𝑑𝑥
𝑑𝑦 2𝑦
(4) Calculate 𝑦(1.2), 𝑦(1.4) given = + 𝑥3 , 𝑦(1) = 0.5
𝑑𝑥 𝑥
𝑑𝑦
(5) Given = −𝑥𝑦2 , 𝑦(0) = 2, ℎ = 0.1. Evaluate y(0.2)
𝑑𝑥
𝑑𝑦
(6) Given = 1 − 𝑦, 𝑦(0) = 0. Evaluate y(0.1) and y(0.2)
𝑑𝑥

Solve by Modified Euler Method

𝑑𝑦
(1) Given = 𝑥2 + 𝑦2 , 𝑦(0) = 1 Find 𝑦(0.1) and y(0.2)
𝑑𝑥
𝑑𝑦
(2) Given = log(𝑥 + 𝑦), 𝑦(0) = 1, ℎ = 0.2. Find 𝑦(0.2)
𝑑𝑥
𝑑𝑦
(3) Compute 𝑦(0.25) given = 2𝑥𝑦, 𝑦(0) = 1
𝑑𝑥
𝑑𝑦
(4) Given = 2 + √𝑥𝑦, 𝑦(1) = 1, ℎ = 0.2. Evaluate y(2)
𝑑𝑥
𝑑𝑦 cos 𝑦
(5) Given = − 0.5𝑦2 , 𝑦(0) = 0, 0 ≤ 𝑥 ≤ 1, ℎ = 0.2.
𝑑𝑥 1+𝑥
𝑑𝑦 1
(6) Compute y for 0 ≤ 𝑥 ≤ 1 given = −5𝑦 + 5𝑥2 + 2𝑥, 𝑦(0) = , ℎ = 0.2
𝑑𝑥 3

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 10 of 12


MA401 – NMCP : Improved Euler Method

A C Programme to implement Improved Euler Method

// A C Programme to Implement Improved Euler Method //


# include <stdio.h>
# include <conio.h>
# include <math.h>

float f(float x, float y)


𝑑𝑦
{ f(x,y) has to be replaced with the differential function 𝑑𝑥
𝑑𝑦
return (f(x,y)); e.g. if 𝑑𝑥 = 𝑥 + 𝑦 then we have to replace f(x,y) with 𝑥 + 𝑦
}

void main()
{
float x0, y0, h, xn, y1;
printf(“\nEnter initial approximations x0, y0 & interval width h:”);
scanf(“%f%f”, &x0, &y0);
printf(“\nEnter the step length : ”);
scanf(“%f”, &h);
printf(“\nEnter the value of x at which y is required”);
scanf(“%f”, &xn);
while (x0 < = xn)
{
printf(“\n When x = %f the value of y = %f “, x0, y0);
y11 = y0+h*f(x0, y0);
x1 = x0+h;
y1 = y0+h*(f(x0,y0)+f(x1,y11))/2;
x0 = x1;
y0 = y1;
}
getch();
}

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 11 of 12


MA401 – NMCP : Improved Euler Method

A C Programme to implement Modified Euler Method

// A C Programme to Implement Modified Euler Method //


# include <stdio.h>
# include <conio.h>
# include <math.h>

float f(float x, float y)


𝑑𝑦
{ f(x,y) has to be replaced with the differential function 𝑑𝑥
𝑑𝑦
return (f(x,y)); e.g. if 𝑑𝑥 = 𝑥 + 𝑦 then we have to replace f(x,y) with 𝑥 + 𝑦
}

void main()
{
float x0, y0, h, xn, x1, y1, y11, y12, y13, e;
printf(“\nEnter initial approximations x0, y0:”);
scanf(“%f%f”, &x0, &y0);
printf(“\nEnter the step length : ”);
scanf(“%f”, &h);
printf(“\nEnter the value of x at which y is required”);
scanf(“%f”, &xn);
e=0.0001; The value of e may be asked from the user
while (x0<=xn) depending on the accuracy of the result desired
{
printf(“\n When x = %f the value of y = %f “, x0, y0);
y11 = y0+h*f(x0, y0);
x1 = x0+h;
y12 = y0+h*(f(x0,y0)+f(x1, y11))/2;
while ((y11-y12)>e)
{
y13 = y0+h*(f(x0,y0)+f(x1, y12))/2;
y11 = y12;
y12 = y13;
}
x0 = x1;
y0 = y12;
}
getch();
}

Copyright©2021, A.A. Basumatary, Deptt. of Mathematics, CIT Kokrajhar. Page 12 of 12

You might also like