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

HW Mat4

The document discusses solving a differential equation numerically over the interval from 0 to 1 using various methods: 1) Analytically, the solution is given as a function of x. 2) Euler's method, Heun's method, and Ralston's method are used to iteratively calculate solutions at step sizes of 0.25. 3) The fourth-order Runge-Kutta method is also used to solve the differential equation numerically over the interval. The results of each method are displayed on a single graph for comparison.

Uploaded by

Zeyad F Saad
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)
39 views

HW Mat4

The document discusses solving a differential equation numerically over the interval from 0 to 1 using various methods: 1) Analytically, the solution is given as a function of x. 2) Euler's method, Heun's method, and Ralston's method are used to iteratively calculate solutions at step sizes of 0.25. 3) The fourth-order Runge-Kutta method is also used to solve the differential equation numerically over the interval. The results of each method are displayed on a single graph for comparison.

Uploaded by

Zeyad F Saad
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/ 13

Numerical Methods Course Home work

Q25.2 Solve the following problem over the interval from x = 0 to 1 using a step size of 0.25 where y(0) =1. Display all your results on the same graph.
dy
=(1+2 x) √ y
dx
(a) Analytically.
(b) Euler’s method.
(c) Heun’s method without the corrector.
(d) Ralston’s method.
(e) Fourth-order RK method.

Solution ……

(a) Analytically.
1
dy
=( 1+2 x ) . dx ≫≫( y ) 2 dy =( 1+ 2 x ) . dx
√y
Integrating x=0 , y = 1

y 1 x

∫ ( y )2 dy=∫ ( 1+2 x ) . dx
1 0

1 1 1
2 y y =x + x 2 x ≫≫ 2 y 2 −2 ( 1 ) 2 =x + x 2−( 0 )
1
2
| 0 |
1
2 x+ x 2 +2 x+ x2 +2 2
y = ≫ ≫ y =( )
2 2
at x = 0 , 0.25 , 0.5 , 0.75 , 1

2 2 2 2
x + x 2 +2 2 0+(0) +2 x + x 2 +2 2 0.25+(0.25) + 2
y ( 0 )=( ) =( ) =1 y ( 0.25 )=( ) =( ) =1.337
2 2 2 2
2 2 2 2
x + x 2 +2 2 0.5+(0.5) +2 x + x 2 +2 2 0.75+(0.75) + 2
y ( 0.5 )=( ) =( ) =1.891 y ( 0.75 )=( ) =( ) =2.743
2 2 2 2
2 2
x + x 2+2 2 1+(1) + 2
y ( 1 )=( ) =( ) =4
2 2
‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

(b) Euler’s method.

when x = 0 , y(0) =1

1 1
y '1=( 1+2 x )( y ) 2 =( 1+2( 0) ) ( 1 ) 2 =1

y i+1 = y i+ ( y '1∗h )=1+(1∗.25)=1.25


Numerical Methods Course Home work
when x = 0.25 , y(0) =1.25

1 1
y '1=( 1+2 x )( y ) 2 =( 1+2( 0.25) ) ( 1.25 ) 2 =1.677

y i+1 = y i+ ( y '1∗h )=1.25+(1.677∗.25)=1.669


when x = 0. 5 , y(0) =1.669

1 1
y '1=( 1+2 x )( y ) 2 =( 1+2( 0.5) ) ( 1.669 ) 2 =2.584

y i+1 = y i+ ( y '1∗h )=1.669+(2.584∗.25)=2.473

when x = 0. 75 , y(0) =2.473

1 1
y '1=( 1+2 x )( y ) 2 =( 1+2(0.75) ) ( 2.473 ) 2 =3.931

y i+1 = y i+ ( y '1∗h )=2.473+(2.473∗.25)=3.464

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

(c) Heun’s method without the corrector.

when x = 0 , y(0) =1

1 1
' 2 2
y =( 1+2 x )( y ) =( 1+2(0) ) ( 1 ) =1

y 0' = yi + y '∗h=1+(1∗.25)=1.25
1 1
' 0 2
y =( 1+2 x ) ( y ' ) =( 1+2(0.25) ) ( 1.25 ) 2 =1.677
1

y 0' + y '1 1.25+1.677


y i+1 = y i+
2 (∗h=1+
2 )
∗0.25=1.334 ( )
when x = 0.25 , y(0) =1.334

1 1
' 2 2
y =( 1+2 x )( y ) =( 1+2(0.25)) ( 1.334 ) =1.733

y 0' = yi + y '∗h=1.334 +(1.733∗0.25)=1.768


1 1
' 0 2
y =( 1+2 x ) ( y ' ) =( 1+2(0.5) ) ( 1.768 ) 2 =2.660
1

y 0' + y '1 1.768+2.660


y i+1 = y i+ ( 2 )
∗h=1.334+
2
∗0.25=1.888 ( )
Numerical Methods Course Home work
when x = 0. 5 , y(0) =1.888

1 1
' 2 2
y =( 1+2 x )( y ) =( 1+2(0.5) ) ( 1.888 ) =2.748

y 0' = yi + y '∗h=1.888+(2.748∗0.25)=2.575
1 1
' 0 2
y =( 1+2 x ) ( y ' ) =( 1+2(0.75) ) ( 2.575 ) 2 =4.012
1

y 0' + y '1 2.575+ 4.012


y i+1 = y i+ ( 2 )
∗h=1.888+
2
∗0.25=2.711 ( )
When x = 0. 75 , y(0) =2.711

1 1
' 2 2
y =( 1+2 x )( y ) =( 1+2(1) ) ( 2.711 ) =4.112

y 0' = yi + y '∗h=2.711+(4.112∗0.25)=3.740
1 1
' 0 2
y =( 1+2 x ) ( y ' ) =( 1+2(1) ) (3.740 )2 =5.802
1

y 0' + y '1 3.740+5.802


y i+1 = y i+ ( 2 )
∗h=2.711+
2
∗0.25=3.904 ( )
‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

(d) Ralston’s method.

when x = 0 , y(0) =1

1 1
k 1=f ( x , y ) =( 1+ 2 x ) ( y )2 = ( 1+ 2(0) ) ( 1 ) 2 =1

3 3
k 2=f ( xi + h , y i + k 1 h)=¿
4 4

y i+1 = y i+ ( 13 k + 23 k )∗h=1+( 13 1+ 23 1.498 )∗0.25=1.333


1 2

when x = 0.25 , y(0) =1.333

1 1
k 1=f ( x , y ) =( 1+ 2 x ) ( y )2 = ( 1+ 2(0.25) ) ( 1.333 ) 2 =1.732

3 3
k 2=f ( xi + h , y i + k 1 h)=¿
4 4
Numerical Methods Course Home work

y i+1 = y i+ ( 13 k + 23 k )∗h=1.333+( 13 1.732+ 23 2.414 )∗0.25=1.879


1 2

when x = 0.5 , y(0) =1.879

1 1
k 1=f ( x , y ) =( 1+ 2 x ) ( y )2 = ( 1+ 2(0.5) ) ( 1.879 ) 2 =2.741

3 3
k 2=f ( xi + h , y i + k 1 h)=¿
4 4

y i+1 = y i+ ( 13 k + 23 k )∗h=1.879+( 13 2.741+ 23 3.674)∗0.25=2.719


1 2

when x = 0.75 , y(0) =2.719

1 1
2 2
k 1=f ( x , y ) =( 1+ 2 x ) ( y ) = ( 1+ 2(0.75) ) ( 2.719 ) =4.122

3 3
k 2=f ( xi + h , y i + k 1 h)=¿
4 4

y i+1 = y i+ ( 13 k + 23 k )∗h=2.719+( 13 4.122+ 23 5.373)∗0.25=4.070


1 2

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

(e) Fourth-order RK method.

when x = 0 , y(0) =1

1 1
2 2
k 1=f ( x , y ) =( 1+ 2 x ) ( y ) = ( 1+ 2(0) ) ( 1 ) =1

1 1
k 2=f ( xi + h , y i + k 1 h)=¿
2 2

1 1
k 3=f (xi + h , y i + k 2 h)=¿
2 2
1 1
k 4=f ( x i +h , y i+ k 3 h)=( 1+2 ( x +h ) ) ( y+ k 3 h ) 2 =( 1+2 ( 0+0.25 ) ) ( 1+1.350∗0.25 ) 2 =1.735
Numerical Methods Course Home work

h 0.25
y i+1 = y i+ ( k 1 +2∗k 2 +2∗k 3 +k 4 )=1+ ( 1+2∗1.325+2∗1.350+1.735 )=1.337
6 6
when x = 0.25 , y(0) =1.337

1 1
k 1=f ( x , y ) =( 1+ 2 x ) ( y )2 = ( 1+ 2(0.25) ) ( 1.337 )2 =1.734

1 1
k 2=f ( xi + h , y i + k 1 h)=¿
2 2

1 1
k 3=f (xi + h , y i + k 2 h)=¿
2 2
1 1
2 2
k 4=f ( x i +h , y i+ k 3 h)=( 1+2 ( x +h ) ) ( y+ k 3 h ) =( 1+2 ( 0.25+0.25 ) ) ( 1.337+2.220∗0.25 ) =2.751

h 0.25
y i+1 = y i+ ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.337+ ( 1.734+2∗2.181+2∗2.220+2.751 ) =1.891
6 6

when x = 0.5 , y(0) =1.891

1 1
2 2
k 1=f ( x , y ) =( 1+ 2 x ) ( y ) = ( 1+ 2(0.5) ) ( 1.891 ) =2.750

1 1
k 2=f ( xi + h , y i + k 1 h)=¿
2 2

1 1
k 3=f (xi + h , y i + k 2 h)=¿
2 2
1 1
k 4=f ( x i +h , y i+ k 3 h)=( 1+2 ( x +h ) ) ( y+ k 3 h ) 2 =( 1+2 ( 0.5+0.25 )) ( 1.891+3.42∗0.25 ) 2 =6.864

h 0.25
y i+1 = y i+ ( k 1 +2 k 2 +2 k 3 +k 4 ) =1.891+ ( 2.75+ 2∗3.364+ 2∗3.42+6.864 )=2.857
6 6
when x = 0.75 , y(0) =2.857

1 1
k 1=f ( x , y ) =( 1+ 2 x ) ( y )2 = ( 1+ 2(0.75) ) ( 2.857 ) 2 =4.226

1 1
k 2=f ( xi + h , y i + k 1 h)=¿
2 2

1 1
k 3=f (xi + h , y i + k 2 h)=¿
2 2
Numerical Methods Course Home work
1 1
2 2
k 4=f ( x i +h , y i+ k 3 h)=( 1+2 ( x +h ) ) ( y+ k 3 h ) =( 1+2 ( 0.75+0.25 ) ) ( 2.857+5.137∗0.25 ) =6.105

h 0.25
y i+1 = y i+ ( k 1 +2 k 2 +2 k 3 +k 4 ) =2.857+ ( 4.226+ 2∗5.06+2∗5.137+6.105 ) =4.140
6 6

x 0 0.25 0.50 0.75 1.00


Analytically 1 1.337 1.891 2.743 4.00
Euler’s method 1 1.250 1.669 2.473 3.464
Heun’s method 1 1.334 1.888 2.711 3.904
Ralston’s method 1 1.333 1.879 2.719 4.071
Fourth-order RK method 1 1.337 1.891 2.857 4.14

4.5

3.5

3
alytically
2.5
Euler’s method
Heun’s method
2
Ralston’s method
Fourth-order RK method
1.5

0.5

0
0 0.25 0.5 0.75 1 1.25

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

Q25.4 Solve the following problem with the fourth-order RK method ,

d2 y dy
2
+0.5 +7 y
dx dx
where y(0) = 4 and y(0) = 0. Solve from x = 0 to 5 with h = 0.5 Plot your results.

Solution ……
Numerical Methods Course Home work

dy
Let = y'
dx

d y' '
=−0.5 y −7 y
dx

x y
y; k 11 k 12 y mid y ,mid ❑ k 21 k 22 y mid y ,mid ❑ k 31 k 32 y end y , end k 41 k 42
0 4 0 0 -28 4 -7 -7 -31.5 2.25 -7.875 -7.875 -11.813 0.0625 -5.906 -5.906 2.516
0.5 1.028 -9.34 -9.34 -2.526 -1.305 -9.97 -9.97 14.12 -1.463 -5.81 -5.81 13.14 -1.875 -2.77 -2.77 14.51
1 -2.147 -3.91 -3.91 16.984 -3.125 0.336 0.336 21.7 -1.389 1.515 1.515 13.68 -1.389 2.93 2.93 8.258
1.5 -2.497 4.09 4.09 15.434 -2.47 7.95 7.95 13.315 -0.51 7.42 7.42 -0.144 1.213 4.02 4.02 -10.50
2 0.7405 6.7 6.7 -8.534 2.24 4.67 4.67 -17.735 1.908 2.27 2.27 -14.5 -0.546 -0.546 -0.546 57.162
2.5 -0.92 5.38 5.38 3.75 0.425 6.32 6.32 -6.135 0.66 3.85 3.85 -6.545 1.005 2.11 2.11 -8.09
3 1.4 2.905 2.905 -11.25 2.13 0.092 0.092 -14.96 1.423 -0.834 -0.834 -9.54 0.983 -1.867 -1.867 -5.95
3.5 1.36 -2.61 -2.61 -8.215 0.7075 -4.66 -4.66 -2.62 0.195 -3.27 -3.27 0.27 -0.275 -2.48 -2.48 3.165
4 -0.386 -3.23 -3.23 4.317 -1.19 -2.15 -2.15 9.43 -0.923 -0.87 -0.87 6.9 -0.821 0.219 0.219 5.64
4.5 -1.14 0.32 0.32 7.82 -1.06 2.28 2.28 6.28 -0.57 1.89 1.89 3.045 -0.195 1.843 1.843 0.444
5 -0.195 0.444 0.444 1.143 -0.084 0.729 0.729 0.223 -0.013 0.5 0.5 -0.15 0.055 0.365 0.365 -0.567

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5
y
-2
y2
-4

-6

-8

-10

-12

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

Q 25.7 Use (a) Euler’s and (b) the fourth-order RK method to solve
2
dy
=−2+4 e−x dz =− y z
dx dx 3
Numerical Methods Course Home work
over the range x = 0 to 1 using a step size of 0.2 with y(0) = 2 and z(0) = 4.

Solution ……

(a) Euler’s method

dy
=−2 y+ 4 e−x
dx

when x = 0 , y(0) =2

y '1=−2 y + 4 e−x =−2 ( 2 ) + 4 e−0=0

y i+1 = y i+ ( y '1∗h )=2+(0∗.2)=2


when x = 0.2 , y(0) =2

y '1=−2 y + 4 e−x =−2 ( 2 ) + 4 e−0.2=−0.725

y i+1 = y i+ ( y '1∗h )=2+(−0.725∗.2)=1.855


when x = 0.4 , y(0) =1.855

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

dz − y z 2 dz −4 x e−x ∗z2
= ≫≫ ≫ =
dx 3 dx 9

when x = 0 , z(0) = 4

2
−4 x e−x∗z 2 −4 (0)e ∗(4)
−0
z i=f ( x , z ) = = =0
9 9

z i+1=z i + ( z '1∗h )=4+ ( 0∗.2 ) =4


when x = 0.2 , z(0) = 4

−4 x e−x∗z 2 −4 ( 0.2 ) e ∗( 4 )2
−0.2
z i=f ( x , z ) = = =−1.164
9 9

z i+1=z i + ( z '1∗h )=4+(−1.164∗.2)=3.77


when x = 0.4 , z(0) = 3.77
Numerical Methods Course Home work

x y z
0 2 4
0.2 2 4
0.4 1.855 3.77
0.6 1.65 3.43
0.8 1.429 3.08
1 1.22 2.78

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

b) the fourth-order RK method


dy
=−2 y+ 4 e−x
dx
when x = 0 , y(0) =2

k 1=f ( x , y ) =−2 y + 4 e− x =−2∗2+ 4 e−0 =0

1 1 0 0.2
( 2 2 )
k 2=f xi + h , y i + k 1 h =−2∗2+ ∗0.2+ 4 e−0+
2 2
=−0.1

1 1 −0.1 0.2
( 2 2 )
k 3=f xi + h , y i + k 2 h =−2∗2+
2
∗0.2+ 4 e−0+
2
=0.09

k 4=f ( x i+ h , y i +k 3 h )=−2∗2+0.09∗0.2+ 4 e−0 +0.2=0.218

h 0.2
y i+1 = y i+ ( k 1 +2∗k 2 +2∗k 3 +k 4 )=2+ ( 0−2∗0.1+ 2∗0.09+ 0.218 )=2.006
6 6
when x = 0.2 , y(0) =2.006

k 1=f ( x , y ) =−2 y + 4 e− x =−2∗2.006 +4 e−0.2=−0.737

1 1 −0.737 0.2
( 2 2 )
k 2=f xi + h , y i + k 1 h =−2∗2.006+
2
∗0.2+ 4 e−0.2 +
2
=−0.711

1 1 −0.711 0.2
( 2 2 )
k 3=f xi + h , y i + k 2 h =−2∗2.006+
2
∗0.2+ 4 e−0.2 +
2
=−0.708

k 4=f ( x i+ h , y i +k 3 h )=−2∗2.006−0.708∗0.2+ 4 e−0.2 +0.2=−1.25


Numerical Methods Course Home work

h 0.2
y i+1 = y i+ ( k 1 +2∗k 2 +2∗k 3 +k 4 )=2.006+ (−0.737−2∗0.711−2∗0.708−1.25 )=1.859
6 6
when x = 0.4 , y(0) =1.845

k 1=f ( x , y ) =−2 y + 4 e− x =−2∗1.845+ 4 e−0.4 =−1.009

1 1 −1.009 0.2
( 2 2 )
k 2=f xi + h , y i + k 1 h =−2∗1.845+
2
∗0.2+ 4 e−0.4 + =−1.01
2

1 1 −1.01 0.2
( 2 2 )
k 3=f xi + h , y i + k 2 h =−2∗1.845+
2
∗0.2+ 4 e−0.4 +
2
=−1.01

k 4=f ( x i+ h , y i +k 3 h )=−2∗1.845−1.041∗0.2+ 4 e−0.4 +0.2=−1.011

h 0.2
y i+1 = y i+ ( k 1 +2∗k 2 +2∗k 3 +k 4 )=1.845+ (−1.009−4∗1.01−1.011 )=1.643
6 6
when x = 0.6 , y(0) =1.643

k 1=f ( x , y ) =−2 y + 4 e− x =−2∗1.643+ 4 e−0.6 =−1.091

1 1 −1.091 0.2
( 2 2 )
k 2=f xi + h , y i + k 1 h =−2∗1.643+
2
∗0.2+ 4 e−0.6 +
2
=−1.100

1 1 −1.1 0.2
( 2 2 )
k 3=f xi + h , y i + k 2 h =−2∗1.643+
2
∗0.2+ 4 e−0.6 +
2
=−1.101

k 4=f ( x i+ h , y i +k 3 h )=−2∗1.643−1.101∗0.2+ 4 e−0.6 + 0.2=−1.111

h 0.2
y i+1 = y i+ ( k 1 +2∗k 2 +2∗k 3 +k 4 )=1.643+ (−1.091−2∗1.1−2∗1.101−1.111 )=1.423
6 6
when x = 0.8 , y(0) =1.423

k 1=f ( x , y ) =−2 y + 4 e− x =−2∗1.423+ 4 e−0.8 =−1.049

1 1 −1.049 0.2
( 2 2 )
k 2=f xi + h , y i + k 1 h =−2∗1.423+
2
∗0.2+ 4 e−0.8 n+
2
=−1.054

1 1 −1.054 0.2
( 2 2 )
k 3=f xi + h , y i + k 2 h =−2∗1.423+
2
∗0.2+ 4 e−0.8 n +
2
=−1.054

k 4=f ( x i+ h , y i +k 3 h )=−2∗1.423−1.054∗0.2+ 4 e−0.8 +0.2=−1.06


Numerical Methods Course Home work

h 0.2
y i+1 = y i+ ( k 1 +2∗k 2 +2∗k 3 +k 4 )=1.423+ (−1.049−4∗1.054−1.06 )=1.212
6 6

dz − y z 2 dz −4 x e−x ∗z2
= ≫≫ ≫ =
dx 3 dx 9
when x = 0 , z(0) = 4

2
−4 x e−x∗z 2 −4 (0) e ∗( 4)
−0
l 1=f ( x , z ) = = =0
9 9

0.2 0.2 ( ) 2
h h (
− 4 ( 0 ) e−0+
2 )(
∗ 4+
2
0 )
(
l 2=f x + , z+ l 1 =
2 2 ) 9
=−0.1778

2
0.2 0.2 (
h h (
− 4 ( 0 ) e−0+
2 )(
∗ 4+
2
−1.778 ) )
(
l 3=f x + , z+ l 2 =
2 2 ) 9
=−0.1762

2
−4 x e−x∗z 2 −4 ( 0 ) e + 0.2∗( 4−0.1762 )
−0
l 4 =f ( x +h , z+l 3 ) = = =−0.325
9 9

h 0.2
z i+1=z i + ( l 1 +2∗l 2 +2∗l 3+ l 4 )=4+ (−0−2∗0.1778−2∗0.1762−0.325 )=3.966
6 6
when x = 0.2 , z(0) = 3.966

2
−4 x e−x∗z 2 −4 ( 0.2 ) e ∗( 3.966 )
−0.2
l 1=f ( x , z ) = = =−1.145
9 9
2
0.2 0.2 (
h h (
− 4 ( 0.2 ) e−0.2 +
2 )(
∗ 3.966+
2
−1.145 ) )
(
l 2=f x + , z+ l 1 =
2 2 ) 9
=−1.244

2
0.2 0.2 (
h h (
− 4 ( 0.2 ) e−0.2 +
2 )(
∗ 3.966+
2
−1.244 ) )
(
l 3=f x + , z+ l 2 =
2 2 ) 9
=−1.238

−4 x e−x∗z 2 −4 ( 0.2 ) e +0.2∗( 3.966−1.238 )2


−0.2
l 4 =f ( x +h , z+l 3 ) = = =−0.707
9 9

h 0.2
z i+1=z i + ( l 1 +2∗l 2 +2∗l 3+ l 4 )=3.966+ (−1.145−2∗1.244−2∗1238−0.707 )=3.739
6 6
Numerical Methods Course Home work
when x = 0.4 , z(0) = 3.739

2
−4 x e−x∗z 2 −4 ( 0.4 ) e ∗ (3.739 )
−0.4
l 1=f ( x , z ) = = =−1.666
9 9
2
0.2 0.2 (
h h (
− 4 ( 0.4 ) e−0.4 +
2 )(
∗ 3.739+
2
−1.666 ) )
(
l 2=f x + , z+ l 1 =
2 2 ) 9
=−1.663

2
0.2 0.2 (
h h (
− 4 ( 0.4 ) e−0.4 +
2 )(
∗ 3.739+
2
−1.663 ) )
(
l 3=f x + , z+ l 2 =
2 2 ) 9
=−1.664

−0.4 2
−4 x e−x∗z 2 −( 4 ( 0.4 ) e + 0.2 )∗( 3.739−1.664 )
l 4 =f ( x +h , z+l 3 ) = = =−0.609
9 9

h 0.2
z i+1=z i + ( l 1 +2∗l 2 +2∗l 3+ l 4 )=3.739+ (−1.666−2∗1.663−2∗1.664−0.609 )=3.441
6 6
when x = 0.6 , z(0) = 3.441

2
−4 x e−x∗z 2 −4 ( 0.6 ) e ∗( 3.441 )
−0.6
l 1=f ( x , z ) = = =−1.733
9 9
2
0.2 0.2 (
h h (
− 4 ( 0.6 ) e−0.6 +
2 )(
∗ 3.441+
2
−1.733 ) )
(
l 2=f x + , z+ l 1 =
2 2 ) 9
=−1.681

2
0.2 0.2 (
h h (
− 4 ( 0.6 ) e−0.6 +
2 )(
∗ 3.441+
2
−1.681 ) )
(
l 3=f x + , z+ l 2 =
2 2 ) 9
=−1.687

−0.6 2
−4 x e−x∗z 2 −( 4 ( 0.6 ) e +0.2 )∗( 3.441−1.681 )
l 4 =f ( x +h , z+l 3 ) = = =−0.522
9 9

h 0.2
z i+1=z i + ( l 1 +2∗l 2 +2∗l 3+ l 4 )=3.441+ (−1.733−2∗1.681−2∗1.687−0.522 )=3.141
6 6
when x = 0.8 , z(0) = 3.141

2
−4 x e−x∗z 2 −4 ( 0.8 ) e ∗( 3.141 )
−0.8
l 1=f ( x , z ) = = =−1.576
9 9
Numerical Methods Course Home work
2
0.2 0.2 (
h h (
− 4 ( 0.8 ) e−0.8 +
2 )(
∗ 3.141+
2
−1.576 ) )
2(
l 2=f x + , z+ l 1 =
2 ) 9
=−1.521

2
0.2 0.2 (
h h (
− 4 ( 0.8 ) e−0.8+
2 )(
∗ 3.141+
2
−1.521 ) )
2(
l 3=f x + , z+ l 2 =
2 ) 9
=−1.527

−0.8 2
−4 x e−x∗z 2 −( 4 ( 0.8 ) e +0.2 )∗( 3.141−1.527 )
l 4 =f ( x +h , z+l 3 ) = = =−0.474
9 9

h 0.2
z i+1=z i + ( l 1 +2∗l 2 +2∗l 3+ l 4 )=3.141+ (−1.576−2∗1.521−2∗1.527−0.474 )=2.87
6 6
x y z
0 2 4
0.2 2 4
0.4 1.855 3.77
0.6 1.65 3.43
0.8 1.429 3.08
1 1.22 2.78

4.5

3.5

2.5 y1
Z1
2 y2
Z2

1.5

0.5

0
0 0.25 0.5 0.75 1 1.25

You might also like