1 numerical solutions of ode dr. asaf varol. 2 what is ode and pde a differential equation is an...

33
1 Numerical Solutions of ODE Dr. Asaf Varol

Upload: theodore-barton

Post on 05-Jan-2016

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

1

Numerical Solutions of ODE

Dr. Asaf Varol

Page 2: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

2

What is ODE and PDE

• A differential equation is an equation which involves derivatives of one or more dependent variables. If there is only one independent variable involved in the equation(s), then the derivatives are referred to as ordinary derivatives. If, however, there is more than one independent variable in the equation, then partial derivatives (PDE) with respect to each of the independent variables are used.

Page 3: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

3

Linear first-order ODEs

dy/dx = x + y y’ = x + y

du/dx + u = 2 u’ + u = 2

Page 4: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

4

Non-Linear first-order ODEs

dy/dx = x + cos(y) y’ = x + cos(y)

du/dt + u2 = 2 u’ + u2 = 2

Page 5: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

5

Linear, second-order ODEs

d2y/dx2 – dy/dx = xy

y’’= -2y + 0.1y’

Page 6: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

6

Non-Linear, second-order ODEs

d2y/dx2 – dy/dx = xy-y

y’’= -2y + 0.1(y’)2

Page 7: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

7

Homogeneous ODEs

• Homogeneous ODE is an equation which contains the dependent variable or its derivatives in every term.

d2y/dx2 – dy/dx = xy-y

y’’= -2y + 0.1(y’)2

Page 8: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

8

Partial Differential Equation

First order, linear PDEwhere for a given function u = u( x, t)

x and t are the independent variables

Ф is the independent variable.

Second-order linear PDEHere, x and y are the independent variables.

Page 9: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

9

Euler’s MethodWe write any first order ODE in the general form as

y = f(x,y) (6.2.1)

where the function f (x,y) represents the derivative (or the slope) of theunknown dependent variable y that is to be determined. Note that the slope ofthe function may depend on itself. For example

y = -xy ; y(0) = 1; i.e. f(x,y) = -xy (6.2.2)is such an ODE.

Euler’s method uses the slope (or the derivative,) S, of the function at aninitial point say denoted by (xi,yi) to determine the value of the function at thenext point (xi+1, yi+1) where xi+1 = xi+ h; h = x being the distance betweenthe two consecutive points in consideration.

Page 10: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

10

Page 11: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

11

Page 12: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

12

Page 13: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

13

Page 14: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

14

Page 15: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

15

MATLAB (Euler)

Page 16: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

16

Plot (Euler)

Page 17: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

17

Page 18: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

18

Example

• EULER METHOD’S• Solving a simple ODE with Euler’s Method• Consider the differential equation y’ = f( x, y ) on a≤ x≥ b.

Let• y’ = x + y; 0 ≤ x ≥ 1 a = 0, b = 1, y(0) = 2.• First, we find the approximate solution for h=0.5 (n = 2),

a very large step size.• The approximation at x1 = 0.5 is• y1=y0 + h (x0 + y0)= 2.0 + 0.5 (0.0 + 2.0) = 3.0• Next, we find the approximate solution, we use n = 20

intervals, so that h = 0.05.

Page 19: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

19

Solution with MATLAB (Euler)

Page 20: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

20

Plot (Euler)

Page 21: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

21

Modified Euler Method

Page 22: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

22

Higher Order Taylor Methods

• One way to obtain a better solution technique is to use more terms in the Taylor series for y in order to obtain higher order truncation error. For example, a second-order Taylor method uses

• y(x+h)=y(x)+hy’(x)+(h2/2)y’’(x)+O(h3)

• O(h3) is the local truncation error

Page 23: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

23

Solving a Simple ODE with Taylor’s Method

• Consider the differential equation

• y’=x + y; 0≤ x ≤1 with a initial condition y(0) = 2.

• To apply the second order Taylor method to the equation, we find

• y’’=d/dx( x+ y) = 1 + y’ = 1 + x + y

• This gives the approximation formula

• y(x + h)=y(x)+hy’(x)+(h2/2)y’’(x)

Page 24: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

24

Cont’d

yi+1=yi+h(xi+yi)+(h2/2)(1+xi+yi)

For n=2 (h=0.5), we find

y1=y0+h(x0+y0)+(h2/2)(1+x0+y0)=

=2+0.5(0+2)+((.5)2/2)(1+0+2)=3.375

y2=y1+h(x1+y1)+(h2/2)(1+x1+y1)= =3.375+0.5(0.5+3.375)+((0.5)2/2)(1+0.5+3.375)=5.9219

Page 25: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

25

MATLAB Program f. Taylor

Page 26: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

26

Plot (Taylor)

Page 27: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

27

RUNGE-KUTTA METHODS

• Runge-Kutta methods are the most popular methods used in engineering applications because of their simplicity and accuracy. One of the simplest Runge-Kutta methods is based on approximating the value of y at xi + h/2 by taking one-half of the change in y that is given by Euler’s method and adding that on to current value yi. This method is known as the midpoint method.

Page 28: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

28

Midpoint Method

• k1=hf(xi,yi) Change in y given by Euler’s method.

• k2=hf(xi+0.5h,yi+0.5k1) Change in y using slope estimate at midpoint

Page 29: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

29

Solving a Simple ODE with Midpoint Method

• Consider the differential equation• y’=x + y; 0≤ x ≤1 with a initial condition (a=0.0, b=0.0),

y(0) = 2.• First, we find the approximate solution for h=0.5 (n=2), a

very large step size.• k1=hf(x0,y0)=0.5(0.0+2.0)=1.0• k2=hf(x0+0.5h,y0+0.5k1)=0.5(0.0+0.5*0.5+2.0+0.5*1.0)=1.

375• Y1=y0+k2=2.0+1.375=3.375• Next, we find the approximate solution y2 at point

x2=0.0+2h=1.0

Page 30: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

30

Cont’d

• k1=hf(x1,y1)=0.5(x1,y1)=0.5(0.5+3.375)=1.9375

• k2=hf(x1+0.5h,y1+0.5k1)=0.5(0.5+0.5*0.5+3.375+0.5*1.9375)=2.547

y2=y1+k2=3.375+2.5469=5.922

Page 31: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

31

MATLAB Prog. f. Midpoint

Page 32: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

32

Plot (Midpoint)

Page 33: 1 Numerical Solutions of ODE Dr. Asaf Varol. 2 What is ODE and PDE A differential equation is an equation which involves derivatives of one or more dependent

33

References• Celik, Ismail, B., “Introductory Numerical Methods for Engineering Applications”,

Ararat Books & Publishing, LCC., Morgantown, 2001 • Fausett, Laurene, V. “Numerical Methods, Algorithms and Applications”, Prentice

Hall, 2003 by Pearson Education, Inc., Upper Saddle River, NJ 07458

• Rao, Singiresu, S., “Applied Numerical Methods for Engineers and Scientists, 2002 Prentice Hall, Upper Saddle River, NJ 07458

• Mathews, John, H.; Fink, Kurtis, D., “Numerical Methods Using MATLAB” Fourth Edition, 2004 Prentice Hall, Upper Saddle River, NJ 07458

• Varol, A., “Sayisal Analiz (Numerical Analysis), in Turkish, Course notes, Firat University, 2001