of 14 /14
UNIT 2 Numerical Methods – II 2.1 NUMERICAL SOLUTION OF SIMULTANEOUS FIRST ORDER ORDINARY DIFFERENTIAL EQUATIONS 2.1.1 Runge-Kutta Method of Fourth Order 1. Let dy dx = f (x, y , z), dz dx = g(x, y , z) be the simultaneous ﬁrst order ordi- nary differential equations with the initial values y(x 0 ) = y 0 , z(x 0 ) = z 0 . The modiﬁed form of expression for computation are as follows. k 1 = hf (x 0 , y 0 , z 0 ); l 1 = hg(x 0 , y 0 , z 0 ) k 2 = hf x 0 + h 2 , y 0 + k 1 2 , z 0 + l 1 2 ; l 2 = hg x 0 + h 2 , y 0 + k 1 2 , z 0 + l 1 2 k 3 = hf x 0 + h 2 , y 0 + k 2 2 , z 0 + l 2 2 ; l 3 = hg x 0 + h 2 , y 0 + k 2 2 , z 0 + l 2 2 k 4 = hf ( x 0 + h, y 0 + k 3 , z 0 + l 3 ) ; l 4 = hg ( x 0 + h, y 0 + k 3 , z 0 + l 3 ) Then according to second order Runge-Kutta method y(x 0 + h) = y 0 + k 2 z(x 0 + h) = z 0 + l 2 According to fourth order Runge-Kutta method y(x 0 + h) = y 0 + 1 6 ( k 1 + 2k 2 + 2k 3 + k 4 ) and z(x 0 + h) = z 0 + 1 6 ( l 1 + 2l 2 + 2l 3 + l 4 )

# 2.1 NUMERICAL SOLUTION OF SIMULTANEOUS FIRST ORDER ORDINARY … Numerical Methods–II 51 Example 1: Given dy dx = z and dz dx =– xz – y with y(0) = 1, z(0) = 0, obtain y and z

others

• View
13

0

Embed Size (px)

Citation preview

UNIT

2Numerical Methods – II

2.1 NUMERICAL SOLUTION OF SIMULTANEOUSFIRST ORDER ORDINARY DIFFERENTIALEQUATIONS

2.1.1 Runge-Kutta Method of Fourth Order

1. Letdydx

= f (x,y,z),dzdx

= g(x,y,z) be the simultaneous first order ordi-

nary differential equations with the initial values y(x0) = y0 , z(x0) = z0.The modified form of expression for computation are as follows.

k1 = h f (x0 ,y0 ,z0); l1 = hg(x0 ,y0 ,z0)

k2 = h f(

x0 +h2,y0 +

k12

,z0 +l12

)

; l2 = hg(

x0 +h2,y0 +

k12

,z0 +l12

)

k3 = h f(

x0 +h2,y0 +

k22

,z0 +l22

)

; l3 = hg(

x0 +h2,y0 +

k22

,z0 +l22

)

k4 = h f(

x0 + h,y0 + k3 ,z0 + l3)

; l4 = hg(

x0 + h,y0 + k3 ,z0 + l3)

Then according to second order Runge-Kutta method

y(x0 + h) = y0 + k2

z(x0 + h) = z0 + l2

According to fourth order Runge-Kutta method

y(x0 + h) = y0 +16

(

k1 + 2k2 + 2k3 + k4)

and

z(x0 + h) = z0 +16

(

l1 + 2l2 + 2l3 + l4)

46 Engineering Mathematics-IV

= .1 [1.11 – 0.1] = 0.101

l4 = hg(

t0 + h, x0 + k3 , y0 + l3)

= 0.1 [1.1005 + 0.1] = 0.12005

∴ x(t0 + h) = x0 +16

[

k1 + 2k2 + 2k3 + k4]

= 1 +16

[0.1 + 2×0.1 + 2×0.1005 + 0.101]

= 1.100333

and

y(t0 + h) = y0 +16

[

l1 + 2l2 + 2l3 + l4]

= 1 +16

[0.1 + 2(0.11) + 2(0.11) + 0.12005]

= 1.1100083

Thus,

x(0.1) = 1.100333 � 1.1

y(0.1) = 1.1100083 � 1.11.

Example 2: Use fourth order Runge-Kutta method to solve the system ofequations

dydx

= 1 + xz;dzdx

= – xy given y(0) = 0, z(0) = 1 at x = 0.3.

Solution: Given simultaneous equations are

dydx

= 1 + xz,dzdx

= – xy and y(0) = 0, z(0) = 1

or, f (x,y,z) = 1 + xz, g(x,y,z) = – xy

Here x0 = 0, y0 = 0, z0 = 1 and given h = 0.3.

Numerical Methods–II 47

Now, we shall compute the following.

k1 = h f (x0 , y0 , z0) = 0.3 [1 + 1×0] = 0.3

l1 = hg(x0 , y0 , z0) = 0.3 [ – 0×0] = 0

k2 = h f(

x0 +h2, y0 +

k12

, z0 +l12

)

= 0.3 [1 + (1)(0.15)] = 0.345

l2 = hg(

x0 +h2, y0 +

k12

, z0 +l12

)

= 0.3 [ – (0.15)(0.15)] = – 0.00675

k3 = h f(

x0 +h2, y0 +

k22

, z0 +l22

)

= 0.3 [(1 + 0.996625)(0.15)] = 0.34485

l3 = h f(

x0 +h2, y0 +

k22

, z0 +l22

)

= 0.3 [ – (0.15)(0.1725)] = – 0.0077625

k4 = h f(

x0 + h, y0 + k3 , z0 + l3)

= 0.3 [1 + (0.99224)(0.3)] = 0.3893

l4 = h f(

x0 + h, y0 + k3 , z0 + l3)

= 0.3 [ – 0.3(.34485)] = – 0.03104

∴ y(x0 + h) = y0 +16

[

k1 + 2k2 + 2k3 + k4]

∴ y(0.3) = 0 +16

[.3 + 2(.345) + 2(0.34485) + 0.3893]

= 0.34483

48 Engineering Mathematics-IV

and

z(x0 + h) = z0 +16

[

l1 + 2l2 + 2l3 + l4]

= 1 +16

[0 + 2( – 0.00675) + 2( – 0.0077625) + ( – 0.03104)]

∴ z(0.3) = 0.98999.

2.1.2 Picard’s MethodLet the simultaneous differential equations be

dydx

= f (x,y,z) anddzdx

= g(x,y,z)

with initial conditions y(x0) = y0 and z(x0) = z0. Then

y1 = y0 +∫

f (x,y0 ,z0) dx, z1 = z0 +∫

g(x,y0 ,z0) dx

y2 = y0 +∫

f (x,y1 ,z1) dx, z2 = z0 +∫

g(x,y1 ,z1) dx

y3 = y0 +∫

f (x,y2 ,z2) dx, z3 = z0 +∫

g(x,y2 ,z2) dx

and so on.

Continuing this process, a sequence of functions of x, i.e., y1 ,y2 ,y3 . . . andz1 ,z2 ,z3 . . . are obtained each giving a better approximations of the desiredsolution.

Example 1: Using Picard’s method find approximate values of y and z corre-

sponding to x = 0.1 given that y(0) = 2, z(0) = 1 anddydx

= x + z,dzdx

= x – y2.

Solution: Given equations are

dydx

= f (x,y,z) = x + z anddzdx

= g(x,y,z) = x – y2

∴ y = y0 +

x∫

x0

f (x,y,z) dx and z = z0 +

x∫

x0

g(x,y,z) dx

Numerical Methods–II 49

First approximation

y1 = y0 +

x∫

x0

f (x,y0 ,z0) dx = 2 +

x∫

0

(x + 1) dx = 2 + x +x2

2

z1 = z0 +

x∫

x0

g(x,y0 ,z0) dx = 1 +

x∫

0

(x – 4) dx = 1 – 4x +12

x2

Second approximation

y2 = y0 +

x∫

x0

f (x,y1 ,z1)dx = 2 +

x∫

0

(

x + 1 – 4x +12

x2)

dx

= 2 + x –32

x2 +x3

6

z2 = z0 +

x∫

x0

g(x,y1 ,z1)dx = 1 +

x∫

0

[

x –

(

2 + x +12

x2)2

]

dx

= 1 + 4x +32

x2 – x3 –x4

4–

x5

20

Third approximation

y3 = y0 +

x∫

x0

f (x,y2 ,z2)dx

= 2 + x –32

x2 –12

x3 –14

x4 –120

x5 –1

120x6

z3 = z0 +

x∫

0

g(x,y2 ,z2)dx

= 1 – 4x –32

x2 –53

x3 +7

12x4 –

3160

x5 +1

12x6 –

1252

x7

and so on.

50 Engineering Mathematics-IV

when x = 0.1

y1 = 2.105, y2 = 2.08517 y3 = 2.08447

z1 = 0.605, z2 = 0.58397 z3 = 0.58672

Thus, y(0.1) = 2.0845, z(0.1) = 0.5867 correct to four decimal places.

2.1.3 Taylor’s Series MethodLet the simultaneous differential equations be

dydx

= f (x,y,z) (1)

anddzdx

= g(x,y,z) (2)

with initial conditions y(x0) = y0 and z(x0) = z0.

If h be the step-size, y1 = y(x0 + h) and z1 = z(x0 + h)

Then Taylor’s algorithm for (1) and (2) gives

y1 = y0 + hy ′0 +h2

2!y ′′0 +

h3

3!y ′′′0 . . . (3)

z1 = z0 + hz ′0 +h2

2!z ′′0 +

h3

3!z ′′′0 . . . (4)

Differentiating (1) and (2) successively we get y ′′,z ′′, etc.

So the values y ′0 ,y′′0 ,y ′′′0 . . . and z ′0 ,z

′′0 ,z ′′′0 . . . are known. Substituting these

in (3) and (4), we obtain y1 ,z1 for the next step.

Similarly,

y2 = y1 + hy ′1 +h2

2!y ′′1 +

h3

3!y ′′′1 . . . (5)

z2 = z1 + hz ′1 +h2

2!z ′′1 +

h3

3!z ′′′1 . . . (6)

Since y1 and z1 are known, we calculate y ′1 , y ′′1 . . . and z ′1 , z ′′1 . . . substitutingthese in (5) and (6) we get y2 and z2.

Proceeding further, we can calculate the other values of y and z step bystep.

Numerical Methods–II 51

Example 1: Givendydx

= z anddzdx

= – xz – y with y(0) = 1, z(0) = 0, obtain

y and z for x = 0.1,0.2,0.3 by Taylor’s series method.Hint:We have

y ′ = z and z ′ = – xz – y

We use Taylor’s series method to find y and z.

2.2 NUMERICAL SOLUTION OF SECOND ORDERORDINARY DIFFERENTIAL EQUATIONS

2.2.1 Picard’s MethodLet the second order differential equation be

d2ydx2 = f

(

x,y,dydx

)

(1)

with y(x0) = y0 and y ′(x0) = y ′0.

Now, letdydx

= z thend2ydx2 =

dzdx

.

Substituting in (1)

dzdx

= f (x,y,z) with y(x0) = y0 and z(x0) = z0

The problem reduces to solving the simultaneous equations

dydx

= z = f1(x,y,z)

dzdx

= f2(x,y,z) subject to y(x0) = y0 and z(x0) = z0 .

By Picard’s method we have

y1 = y0 +

x∫

x0

f1(x,y0 ,z0) dx, z1 = z0 +

x∫

x0

f2(x,y0 ,z0) dx

y2 = y0 +

x∫

x0

f1(x,y1 ,z1) dx, z2 = z0 +

x∫

x0

f2(x,y1 ,z1) dx

Numerical Methods–II 53

= 0.5 +

x∫

0

(

.1 – 0.2x2

2– 0.5x

)

dx, z2 = 0.1 +

x∫

0

– 2x(

0.1 –.22

x2 – .5x)

– (0.5 + 0.1x) dx

= 0.5 + 0.1x – 0.2x3

6– 0.5

x2

2, = 0.1 – .2

x2

2+ 0.2

x4

4+ 1

x3

3

– 0.5x – 0.1x2

2

and so on.

when x = 0.1

y1 = 0.51 y2 = 0.5074

z1 = y ′1 = 0.049 y ′2 = z2 = 0.0488

∴ y(0.1) = 0.5074

y ′(0.1) = 0.0488

Example 2: Using Picard’s method, obtain the second approximation to thesolution of

d2ydx2 = x3 dy

dx+ x3y so that y(0) = 1, y ′(0) =

12.

Solution: Given the second order differential equation is

d2ydx2 = x3 dy

dx+ x3y with y(0) = 1, y ′(0) =

12

Letdydx

= z so thatd2ydx2 =

dzdx

dydx

= z anddzdx

= x3z + x3 y with y(0) = 1, z(0) =12.

= f (x,y,z) = f1(x,y,z)

By Picard’s methods,

54 Engineering Mathematics-IV

First approximation

y1 = y0 +

x∫

x0

f (x y0 z0)dx z1 = z0 +

x∫

x0

f2(x, y0 z0) dx

= 1 +

x∫

0

12

dx =12

+

x∫

0

(

12

x3 + 1x3)

dx =12

+∫ 3

2x3dx

= 1 +x2

=12

+3x4

8Second approximation

y2 = y0 +

x∫

x0

f (x, y1 , z1) dx z2 = z0 +∫ x

x0f (x,y1 ,z1) dx

= 1 +

x∫

0

(

12

+3x4

8

)

dx =12

+∫ x

0

(

x3(

12

+3x4

8

)

+ x3(

1 +x2

)

)

dx

= 1 +x2

+3x5

x0=

12

+

x∫

0

(

x3

2+

38

x7 + x3 +x4

2

)

dx

=12

+x4

8+

3x8

64+

x4

4+

x5

10

=12

+3x4

8+

x5

10+

3x8

64.

Example 3: Using Picard’s method find the solution of the equation

y ′′ + xy ′ + y = 0, with y(0) = 1 y ′(0) = 0 for x = 0.1 and 0.3.

Solution: Given equation is

y ′′ + xy ′ + y = 0 with y(0) = 1, y ′(0) = 0.

Letdydx

= y ′ = z so thatd2ydx2 = y ′′ =

dzdx

dydx

= z anddzdx

= – xz + y with y(0) = 1, z(0) = 0

= f (x,y,z), = f1(x,y,z).

56 Engineering Mathematics-IV

when x = 0.1

y1(0.1) = 1 y2(0.1) = 0.955, y3(0.1) = 0.99501

z1(0.1) = – 0.1 z2(0.1) = – 0.099, z3(0.1) = – 0.0995

∴ y(0.1) = 0.99501

z(0.1) = y ′(0.1) = – 0.0995

when x = 0.3

y1(0.3) = 1 y2(0.3) = 0.955 y3(0.3) = 0.9556

z1(0.3) = – 0.3 z2(0.3) = – 0.291, z3(0.3) = – 0.2911

∴ y(0.3) = 0.9556

z(0.3) = y ′(0.3) = – 0.2911.

2.2.2 Runge-Kutta MethodLet the second order differential equation be

d2ydx2 = f

(

x, y,dydx

)

. . .(1) with y(x0) = y0 , y ′(x0) = y ′0 .

Now, letdydx

= z so thatd2ydx2 =

dzdx

dydx

= z anddzdx

= f (x,y,z)

= f1(x,y,z), = f2(x,y,z) with y(x0) = y0 , z(x0) = z0 .

The problem reduces to solving the simultaneous equations

dydx

= z = f1(x,y,z) anddzdx

= f2(x,y,z) with y(x0) = y0 and z(x0) = z0 .

Starting at(

x0 ,y0 ,z0)

and taking the step-sizes for x, y, z to be h, k, l respec-tively, the Runge-Kutta method gives

Numerical Methods–II 57

K1 = h f1(x0 ,y0 ,z0) l1 = h f2(x0 ,y0 ,z0)

K2 = h f1

(

x0 +12

h, y0 +k12

, z0 +l12

)

l2 = h f2

(

x0 +h2, y0 +

k12

, z0 +l12

)

k3 = h f1

(

x0 +h2, y0 +

k22

, z0 +l22

)

l3 = h f2

(

x0 +h2, y0 +

k22

, z0 +l22

)

k4 = h f1(

x0 + h, y0 + k3 , z0 + l3)

l4 = h f2(

x0 + h, y0 + h3 , z0 + l3)

∴ y1 = y0 +16

(

k1 + 2k2 + 2k3 + k4)

z1 = z0 +h6

(

l1 + 2l2 + 2l3 + l4)

Example 1: Using Runge-Kutta method solve

y ′′ = xy ′2 – y2 for x = 0.2 correct to 4 decimal places initial conditions arex = 0, y = 1, y ′ = 0.

Solution: Given equation of second order is

y ′′ = xy ′2 – y2 with x = 0, y = 1, y ′ = 0

Letdydx

= z = f1(x,y,z), then

dzdx

= xz2 – y2 = f2(x,y,z) with x0 = 0, y0 = 1, z0 = 0

we compute k1 , k2 , k3 , k4 for f1(x, y, z) and l1 , l2 , l3 , l4 for f2(x, y, z).

∴ by Runge-Kutta formulae, we have

k1 = h f1(x0 ,y0 ,z0) l1 = h f2(x0 ,y0 ,z0)

= 0.2(0) = 0 = 0.2( – 1) = – 0.2

k2 = h f1

(

x0 +h2, y0 +

k12

, z0 +l12

)

l2 = h f2

(

x0 +h2, y0 +

k12

, z0 +l12

)

= 0.2( – 0.1) = – 0.02 = 0.2( – 0.999) = – 0.1998

k3 = h f1

(

x0 +h2, y0 +

k22

, z0 +l22

)

l3 = h f2

(

x0 +h2, y0 +

k22

, z0 +l22

)

= 0.2( – 0.0999) = – 0.02 = 0.2( – 0.9791) = – 0.1958

Numerical Methods–II 59

Letdydx

= z thend2ydx2 =

dzdx

.

Substituting in (1)

dzdx

= f (x,y,z) with y(x0) = y0 and z(x0) = z0

The problem reduces to solving the simultaneous equations.

dydx

= z = f1 (x,y,z)

dzdx

= f2 (x,y,z) subject to y(x0) = y0 , and z(x0) = z0.

The predictor and corrector formulae can be written as

y(P)n + 1 = yn – 3 +

4h3

[

2y ′n – 2 – y ′n – 1 + 2y ′n]

z(P)n + 1 = zn – 3 +

4h3

[

2z ′n – 2 – z ′n – 1 + 2z ′n]

and

y(c)n + 1 = yn – 1 +

h3

[

y ′n – 1 + 4y ′n + y ′n + 1

]

z(c)n + 1 = zn – 1 +h3

[

z ′n – 1 + 4z ′n + z ′n + 1

]

In particular when n = 3

y(P)4 = y0 +

4h3

[

2y ′1 – y ′2 + 2y ′3]

z(P)4 = z0 +

4h3

[

2z ′1 – z ′2 + 2z ′3]

(2)

and

y(c)4 = y2 +

h3

[

y ′2 + 4y ′3 + y ′4]

z(c)4 = z2 +h3

[

z ′2 + 4z ′3 + z ′4]

(3)

(2) is called Milne’s predictor formula and (3) is called Milne’s corrector for-mula.

60 Engineering Mathematics-IV

Example 1: Givend2ydx2 + x

dydx

+ y = 0, y(0) = 1, y ′(0) = 0 obtain y for

x=0, 0.1, 0.2, 0.3 by any method. Further compute y(0.4) by Milne’s method.

Solution: The given equation is

y ′′ + xy ′ + y = 0 . . .(1) with y(0) = 1, y ′(0) = 1

Let y ′ = z then y ′′ = z ′

∴ z ′ + xz + y = 0 and y ′ = z

dydx

= y ′ = z = f1(x,y,z) with y(0) = 1

dzdx

= z ′ = f2(x,y,z) = – xz – y with z(0) = 0

We use Taylor’s series method to find y. Differentiating (1) n times we get

yn + 2 + xyn + 1 + nyn + yn = 0

At x = 0,(

yn + 2)

0= – (n + 1)yn

∴ y(0) = 1 gives y2(0) = – 1, y(0)4 = 32, y(0)

6 = – 5×3

and y1(0) = 0 gives y3(0) = y5(0) = . . . = 0.

Expand y(x) by Taylor’s series

y(x) = y(0) + xy1(0) +x2

2!y2(0) +

x3

3!y3(0) + . . .

∴ y(x) = 1 –x2

2!+

34!

x4 –5×3

6!x6 + . . . (2)

and z(x) = y ′(x) = – x +12

x3 –18

x5 . . . = – xy (3)

From (2) we have

y(0.1) = 1 –(0.1)2

2+

18(.1)4 + . . . = 0.995

y(0.2) = 1 –(0.2)2

2+

(0.2)4

8+ . . . = 0.9802

y(0.3) = 1 –(0.3)2

2+

(0.3)4

8–

(0.3)6

48. . . = 0.956.

62 Engineering Mathematics-IV

and

y(0.4) = y(0.2) +h3

[

y ′(0.2) + 4y ′(0.3) + y ′(0.4)]

= – 0.9802 +

(

0.13

)

[ – 0.196 – 1.1452 – 0.3692]

= 0.9232

Hence, y(0.4) = 0.9232 and y(0.4) = – 0.3692.

Example 2: Givend2ydx2 + 2x

dydx

+ y = 0 and y(0) = 0.5,y ′(0) = 0.1 obtain y

for x = 0, 0.1, 0.2, 0.3 by any suitable method. Hence, apply Milne’s methodto compute y(0.4).

Example 3: Given y ′′ = xy ′2 – y2 and y(0) = 1, y ′(0) = 0 obtain y forx = 0, 0.1, 0.2, 0.3 by Taylor’s series method. Hence, apply Milne’s methodto compute y(0.4).

Ans: y(0.4) = 0.9232

2.2.4 Taylor’s Series MethodExample 1: Given y ′′ + xy ′ + y = 0, y(0) = 1, y ′(0) = 0. Obtain y forx = 0, 0.1, 0.2, 0.3 by Taylor’s series method.

Solution: Given second order differential equation is

y ′′ + xy ′ + y = 0 (1)

Let y ′ = z then y ′′ = z ′

∴ z ′ + xz + y = 0; y ′ = z (2)

We use Taylor’s series method to find y.Differentiating the given equation n times we get

yn + 2 + xyn + 1 + nyn + yn = 0

At x = 0,(yn + 2)0 = – (n + 1)yn

∴ y(0) = 1 gives y2(0) = – 1, y4(0) = 3, y6(0) = – 5× 3 and y1(0) givesy3(0) = y5(0) = . . . = 0