Вы находитесь на странице: 1из 20

CHAPTER 8b.

DIFFERENTIAL EQUATIONS
A. J. Clark School of Engineering Department of Civil and Environmental Engineering

by

Dr. Ibrahim A. Assakkaf


Spring 2001

ENCE 203 - Computation Methods in Civil Engineering II Department of Civil and Environmental Engineering University of Maryland, College Park

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Fundamental Case
Assume that the problem is a first-order differential equation of the form
dy = f (x ) dx subject to y = y0 at x = x0 (5)

If the variables are separated and the integration is carried out on both sides, then y x (6) dy = f (x )dx
y0 x0
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 22

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Fundamental Case
Or
yy =
0

x0

f (x ) dx
x0

y y0 =

f (x ) dx
x

y ( x) = y0 + f (x ) dx
x0
ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

(7)
Assakkaf

Slide No. 23

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Fundamental Case
Recall Taylors Series Expansion
h 2 (2 ) h 3 (3 ) h n (n ) f (x0 ) + f (x0 ) + ... + f (x0 ) + Rn +1 2! 3! n!

f (x0 + h ) = f (x0 ) + hf (1) (x0 ) +

where x0 = base value or starting value x = the point at which the value of the function is needed h = x x0 = distance between x0 and x (step size) n! = factorial of n = n(n-1) (n 2)1 f(n) = indicates the nth derivative of the function f(x) Rn+1 = the remainder of Taylor series expansion
ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

(8)

Assakkaf

Slide No. 24

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Fundamental Case

Taylors Series Expansion


Eq. (8) can be expressed as
g (x ) = g (x0 ) + (x x0 )g (x0 ) +

(x x0 )2 g (x ) 0
2!

(x x0 ) +
Or
3!
dy y (x ) = y0 + (x x0 ) dx + 3!

(9a)

g (x0 ) + L
+

(x x0 )2
2! +L
x = x0

x = x0 3

d2y dx 2

x = x0

(x x0 )

d y dx 3

(9b)
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 25

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Fundamental Case
Taylors Series Expansion

Comparing Eq. 9b and Eq. 7, we can evaluate the integral of Eq. 7 by a Taylor Series Expansion: 2 3 ( ( dy x x0 ) d 2 y x x0 ) d 3 y + + +L y (x ) = y0 + (x x0 ) dx x = x0 2! dx 2 x = x 3! dx 3 x = x

y ( x) = y0 + f (x )
x0
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 26

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Fundamental Case
Taylors Series Expansion
In view of the integral of the second equation, the comparison implies that

x0

f (x ) = (x x0 )

dy dx

+
x = x0

(x x0 )2 d 2 y
2! dx 2
x = x0

(x x0 )3 d 3 y
3! dx 3
x = x0

+L

Therefore, Equations 9b and 7 can be used to solve first order equations.


Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 27

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 1 - Taylor Series Expansion


Solve the following differential equation using Taylors series expansion:
dy = 3x 2 dx such that y = 1 at x = 1

x0 = 1 y0 = 1

The higher-order derivative can be obtained as follows:


d 2x = 6x dx 2 d3y =6 dx 3 dny = 0 for n 4 dx n
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 28

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 1 (contd) - Taylor Series Expansion


Using the Taylors series expansion of Eq. 9b gives (x x0 )2 d 2 y + (x x0 )3 d 3 y dy y (x ) = y + (x x ) +
0 0

dx

x = x0

2!

dx 2

x = x0

3!

dx 3

x = x0

y (x ) = 1 + (x 1) 3 x

2 0

2 3 x 1) x 1) ( ( (6 x0 ) + (6) )+

Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 29

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 1(contd) - Taylor Series Expansion


Substituting for x0 = 1 in the last equation, gives the solution of the differential equation

y (x ) = 1 + (x 1)(3) + 3(x 1) + (x 1)
2

Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 30

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 1(contd) y (x ) = 1 + (x 1)(3)+ 3(x 1) + (x 1)


2

x 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2

One Term 1 1 1 1 1 1 1 1 1 1 1

Two Terms 1 1.3 1.6 1.9 2.2 2.5 2.8 3.1 3.4 3.7 4

y (x ) Three Terms 1 1.33 1.72 2.17 2.68 3.25 3.88 4.57 5.32 6.13 7

Four Terms 1 1.331 1.728 2.197 2.744 3.375 4.096 4.913 5.832 6.859 8
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 31

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 1(contd)
The exact solution can be obtained as follows:
y

dy = 3x dx
2 1 1 x 3x 3 y 1 = = x3 1 3 1 x

y 1 = x3 1 y = x3
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 32

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 1(contd)
One Term 1 1 1 1 1 1 1 1 1 1 1 Two Terms 1 1.3 1.6 1.9 2.2 2.5 2.8 3.1 3.4 3.7 4

y = x3
Four Terms 1 1.331 1.728 2.197 2.744 3.375 4.096 4.913 5.832 6.859 8 TRUE 1 1.331 1.728 2.197 2.744 3.375 4.096 4.913 5.832 6.859 8
Assakkaf

x 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2

y (x ) Three Terms 1 1.33 1.72 2.17 2.68 3.25 3.88 4.57 5.32 6.13 7

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 33

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 1(contd) Taylor Series


Examining the table, we notice that the Taylors series solution for this example gives no error when using 4 terms. This is because, the derivatives beyond the third equal to zero. In this case, Taylors series expansion provides the true solution when all the terms are used.
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 34

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

General Case
Assume that the problem is a first-order ordinary differential equation of the following form:
dy = f (x, y ) dx subject to y = y0 at x = x0

g (x ) = g (x0 , y0 ) + (x x0 )g (x0 , y0 ) + 3!

In this case the Taylor series expansion is 2


(x x0 )
2! g (x0 , y0 )

(x x0 )3 g (x , y ) + L + 0 0
ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

(10)
Assakkaf

Slide No. 35

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

General Case
Or in equivalent form, Taylor series can be given as
dy y (x, y ) = y0 + (x x0 ) dx + 3! +

(x x0 )2
2! +L

x = x0 y = y0

d2y dx 2

x = x0 y = y0

(x x0 )3 d 3 y
dx
3 x = x0 y = y0

(11)

Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 36

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 2 - Taylor Series Expansion


Solve the following differential equation using Taylors series expansion:
dy = 3x 2 y dx such that y = 1 at x = 1

x0 = 1 y0 = 1

The higher-order derivatives can be obtained as follows:


d2y dy = 6 xy + 3 x 2 dx 2 dx
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 37

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 2 - Taylor Series Expansion


d2y dy = 6 xy + 3 x 2 = 6 xy + 3x 2 (3x 2 y ) dx 2 dx = 6 xy + 9 x 4 y d3y dy dy = 6 y + 6 x + 36 x 3 y + 9 x 4 3 dx dx dx 2 3 = 6 y + 6 x(3x y )+ 36 x y + 9 x 4 (3x 2 y ) = 6 y + 6 x(3x 2 y )+ 36 x 3 y + 27 x 6 y
d2y dx 2
x0 =1 y0 =1

= 15

d3y dx 3

x0 =1 y0 =1

= 87

Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 38

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 2 (contd) - Taylor Series Expansion


Using the Taylors series expansion of Eq. 11 gives
dy y (x, y ) = y0 + (x x0 ) dx
x = x0 y = y0

(x x0 )2
2!

d2y dx 2

x = x0 y = y0

(x x0 )3 d 3 y
3! dx 3
x = x0 y = y0

2 3 x 1) x 1) ( ( y (x, y ) = 1 + (x 1)(3) + (15) + (87 )

Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 39

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 2 (contd) - Taylor Series Expansion


Substituting for x0 = 1 and y0 = 1 in the last equation, gives the solution of the differential equation for four terms as

y (x ) = 1 + (x 1)(3) + 7.5(x 1) + 14.5(x 1)


2

Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 40

10

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 2 (contd) - Taylor Series Expansion y(x ) = 1 + (x 1)(3) + 7.5(x 1) + 14.5(x 1)


2

x 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2

y (x ) One Term Two Terms Three Terms 1 1 1 1 1.3 1.375 1 1.6 1.9 1 1.9 2.575 1 2.2 3.4 1 2.5 4.375 1 2.8 5.5 1 3.1 6.775 1 3.4 8.2 1 3.7 9.775 1 4 11.5

Four Terms 1 1.3895 2.016 2.9665 4.328 6.1875 8.632 11.7485 15.624 20.3455 26
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 41

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 2 (contd)
The exact solution can be obtained as follows:
dy dy = 3x 2 y = 3x 2 dx dx y 1 1 0 x x 3x3 ln y ln 1 = = x3 1 3 1 ln y = x 3 1 y = ex
3

1
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 42

11

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 2 (contd) - Taylor Series y = e x 1 Expansion


3

x 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2

y (x ) One Term Two Terms Three Terms 1 1 1 1 1.3 1.375 1 1.6 1.9 1 1.9 2.575 1 2.2 3.4 1 2.5 4.375 1 2.8 5.5 1 3.1 6.775 1 3.4 8.2 1 3.7 9.775 1 4 11.5

Four Terms 1 1.390 2.016 2.967 4.328 6.188 8.632 11.749 15.624 20.346 26.000

TRUE 1 1.392 2.071 3.310 5.720 10.751 22.109 50.049 125.462 350.374 1096.633
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 43

Taylor Series Expansion


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 2 (contd) - Taylor Series Expansion


Viewing the results of the solution based on Taylor series expansion, we notice that as the number of terms increases, the accuracy of the solution improves. Also, as the step size decreases, the accuracy of the solution improves.
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 44

12

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Eulers Method
As we noticed in the previous example, in some cases the derivatives are not easily computed. Therefore, the Taylor series of Eqs. 9, 10, and 11 can be truncated so that only the term with the first derivative is used.

Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 45

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Eulers Method
The value of the dependent variable y = g(x) can be computed using
g (x ) = g (x0 , y0 ) + (x x0 )g (x0 , y0 ) + e or dy y (x ) = y0 + (x x0 ) dx
x = x0 y = y0

(12a) (12b)

+e

Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 46

13

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Eulers Method
For better accuracy, (x x0) should be made small. Notice that (x x0) = x = h The above equations can be rewritten in a more compact form for computer implementation as

yi +1 = yi + hf (xi , yi )

Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 47

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Eulers Method
The iterative procedure for basic Eulers method is given by

yi +1 = yi + hf (xi , yi )
where
h = x x0 f (x0 , y0 ) = g (x0 , y0 ) =
ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

(13)

dy dx

x = x0 y = y0
Assakkaf

Slide No. 48

14

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 3 Eulers Method


Solve the following differential equation for 0 x 1 using a step size of h = 0.1:
dy 1 y=0 dx 2 such that y = 1 at x = 0

Here we have
y (0 ) = 1
ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

or

x0 = 0 y0 = 1
Assakkaf

Slide No. 49

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 3 (contd) Eulers Method


First Iteration (i = 0):
yi +1 = yi + hf (xi , yi ) y1 = y0 + hf (x0 , y0 ) f (x0 , y0 ) = dy dx x0 = 0, y0 = 1, and h = 0.1
x0 = 0 y0 =1

1 1 1 y = (1) = 2 2 2

1 y1 = 1 + 0.1 = 1 + 0.05 = 1.05 2


Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 50

15

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 3 (contd) Eulers Method


Second Iteration (i = 1):
yi +1 = yi + hf (xi , yi ) y2 = y1 + hf (x1 , y1 ) f (x1 , y1 ) = dy dx x1 = 0.1, y1 = 1.05, and h = 0.1
x1 = 0.1 y0 =1.05

1 1 y = (1.05) = 0.5250 2 2

y2 = 1.05 + 0.1(0.5250) = 1.05 + 0.0525 = 1.1025


Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 51

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 3 (contd) Eulers Method


Third Iteration (i = 2):
yi +1 = yi + hf (xi , yi ) y3 = y2 + hf (x2 , y2 ) f (x1 , y1 ) = dy dx x2 = 0.2, y2 = 1.1025, and h = 0.1
x1 = 0.2 y0 =1.1025

1 1 y = (1.1025) = 0.55125 2 2

y3 = 1.1025 + 0.1(0.55125) = 1.157625


Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 52

16

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 3 (contd) Eulers Method


See the spreadsheet output in the next viewgraph for the rest of the iterations. Expression for the exact solution can be obtained as follows: x =0
dy 1 dy 1 = y = dx dx 2 y 2 y0 x0
y x

ln 1 = 0

ln y ln 1 =
x

1 (x x0 ) ln y = 1 x 2 2

y = e2
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 53

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 3 (contd) Eulers Method


i 0 1 2 3 4 5 6 7 8 9 10 x 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 xi 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 yi 1 1.050000 1.102500 1.157625 1.215506 1.276282 1.340096 1.407100 1.477455 1.551328 1.628895
1 x

f (x i , y i ) 0.5 0.525000 0.551250 0.578813 0.607753 0.638141 0.670048 0.703550 0.738728 0.775664 0.814447

y (Euler) 1.050000 1.102500 1.157625 1.215506 1.276282 1.340096 1.407100 1.477455 1.551328 1.628895

y (True) % Error 1 1.051271 0.12 1.105171 0.24 1.161834 0.36 1.221403 0.48 1.284025 0.60 1.349859 0.72 1.419068 0.84 1.491825 0.96 1.568312 1.08 1.648721 1.20

True Function : y = e 2

Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 54

17

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 4 - Taylor Series Expansion


Solve the following differential equation using Eulers method for 1 x 2 with a step size of h = 0.1:

dy = 3x 2 dx

such that y = 1 at x = 1
y (1) = 1 or x0 = 1 y0 = 1
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 55

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 4 (contd) Eulers Method


First Iteration (i = 0):
yi +1 = yi + hf (xi , yi ) y1 = y0 + hf (x0 , y0 ) f (x0 , y0 ) = dy dx x0 = 1, y0 = 1, and h = 0.1
x0 =1 y0 =1

= 3x 2 = 3(1) = 3
2

y1 = 1 + 0.1(3) = 1 + 0.3 = 1.30


Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 56

18

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 4 (contd) Eulers Method


Second Iteration (i = 1):
yi +1 = yi + hf (xi , yi ) y2 = y1 + hf (x1 , y1 ) f (x1 , y1 ) = dy dx x1 = 1.1, y1 = 1.30, and h = 0.1
x1 = 0.1 y0 =1.30

= 3x 2 = 3(1.1) = 3.630
2

y2 = 1.30 + 0.1(3.630) = 1.6630


Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 57

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 4 (contd) Eulers Method


Third Iteration (i = 2):
yi +1 = yi + hf (xi , yi ) y3 = y2 + hf (x2 , y2 ) f (x1 , y1 ) = dy dx x2 = 1.2, y2 = 1.663, and h = 0.1
x1 =1.2 y0 =1.663

= 3 x 2 = 3(1.2) = 4.320
2

y3 = 1.663 + 0.1(0.4.320) = 2.095


Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 58

19

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 4 (contd) Eulers Method


See the spreadsheet output in the next viewgraph for the rest of the iterations. Expression for the exact solution can be obtained as follows:
y

dy = 3x dx
2 1 1

x0 = 1

y0 = 1
x 1

y 1 =

3x 3

3 x

= x3

y 1 = x3 1 y = x3
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 59

First-order Ordinary Differential Equations


A. J. Clark School of Engineering Department of Civil and Environmental Engineering

Example 4 (contd) Eulers Method


x 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 xi 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 yi 1 1.300000 1.663000 2.095000 2.602000 3.190000 3.865000 4.633000 5.500000 6.472000 7.555000 f (x i , y i ) 3 3.63 4.32 5.07 5.88 6.75 7.68 8.67 9.72 10.83 12 y (Euler) 1.300000 1.663000 2.095000 2.602000 3.190000 3.865000 4.633000 5.500000 6.472000 7.555000 y (True) % Error 1 1.331 2.33 1.728 3.76 2.197 4.64 2.744 5.17 3.375 5.48 4.096 5.64 4.913 5.70 5.832 5.69 6.859 5.64 8 5.56

i 0 1 2 3 4 5 6 7 8 9 10

True Function : y = x 3
Assakkaf

ENCE 203 CHAPTER 8b. DIFFERENTIAL EQUATIONS

Slide No. 60

20

Вам также может понравиться