1 numerical solutions of ode dr. asaf varol. 2 what is ode and pde a differential equation is an...
TRANSCRIPT
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 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.
3
Linear first-order ODEs
dy/dx = x + y y’ = x + y
du/dx + u = 2 u’ + u = 2
4
Non-Linear first-order ODEs
dy/dx = x + cos(y) y’ = x + cos(y)
du/dt + u2 = 2 u’ + u2 = 2
5
Linear, second-order ODEs
d2y/dx2 – dy/dx = xy
y’’= -2y + 0.1y’
6
Non-Linear, second-order ODEs
d2y/dx2 – dy/dx = xy-y
y’’= -2y + 0.1(y’)2
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
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.
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.
10
11
12
13
14
15
MATLAB (Euler)
16
Plot (Euler)
17
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.
19
Solution with MATLAB (Euler)
20
Plot (Euler)
21
Modified Euler Method
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
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)
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
25
MATLAB Program f. Taylor
26
Plot (Taylor)
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.
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
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
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
31
MATLAB Prog. f. Midpoint
32
Plot (Midpoint)
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