Presentation is loading. Please wait.

Presentation is loading. Please wait.

ODEs: Initial-Value Problems

Similar presentations


Presentation on theme: "ODEs: Initial-Value Problems"— Presentation transcript:

1 ODEs: Initial-Value Problems
Chapter 20 ODEs: Initial-Value Problems

2 Differential Equations
There are ordinary differential equations - functions of one variable And there are partial differential equations - functions of multiple variables

3 Order of differential equations
1st order (falling parachutist) 2nd order (mass-spring system with damping) etc.

4 Higher-Order ODE’s Can always turn a higher order ODE into a set of 1st order ODEs Example: Let then So solutions to first-order ODEs are important

5 Linear and Nonlinear ODEs
Linear: No multiplicative mixing of variables, no nonlinear functions Nonlinear: anything else

6 Ordinary Differential Equations
ODEs show up everywhere in engineering Dynamics (Newton’s 2nd law) Heat conduction (Fourier’s law) Diffusion (Fick’s law)

7 Example of an ODE x k f(t) What order is this ODE? If f(t) = 0, ODE is homogenous. If f(t) is not equal to 0, ODE is non-homogenous. m c kx Free-body diagram f(t) m

8 Solutions for ODEs The solution for the homogenous ODE.
The solution for the non-homogenous ODE The arbitrary constants C1 & C2 are determined by the Initial-value or Boundary-value conditions.

9 Initial-Value & Boundary-Value Conditions
The I-V Conditions All conditions are given at the same value of the independent variable. The B-V Conditions Conditions are given at the different values of the independent variable. The numerical schemes for solving Initial-value and boundary-value are different.

10 Ordinary Differential Equations
I-V Problems Euler’s and Heun's methods Runge-Kutta methods Adaptive Runge-Kutta Multistep methods* Adams-Bashforth-Moulton methods*

11 Ordinary Differential Equations
1st order Ordinary differential equations (ODEs) Initial value problems Numerical approximations New value = old value + slope × step size

12 New value = old value + slope*step size
Runge-Kutta Methods Runge Kutta methods (One Step Methods) Idea is that New value = old value + slope*step size Slope is generally a function of t, hence y(t) Different methods differ in how to estimate 

13 One-Step Method All one-step methods can be expressed in this general form, the only difference being the manner in which the slope is estimated

14 The solution of ODE depends on the initial condition
Initial Conditions The solution of ODE depends on the initial condition Same ODE, but with different initial conditions t

15 Euler’s method (First-order Taylor Series Method)
Approximate the derivative by finite difference Local truncation error or

16 Euler’s Method Euler’s (Euler-Cauchy or point-slope) method
Use the slope at ti to predict yi+1

17 Euler’s method Straight line approximation y0 t0 h t1 h t2 h t3

18 Example: Euler’s Method
Analytic solution Euler method h = 0.50

19 Example: Euler’s Method

20 Euler’s method: y h = 0.25 1 h = 0.5 t 0.25 0.5 0.75 1.0

21 Euler’s Method (modified M-file)

22 Euler’s Method >> tt=0:0.01*pi:pi;
>> ye=1.5*exp(-tt)+0.5*sin(tt)-0.5*cos(tt); >> [t,y]=Eulode('example2_f',[0 pi],1,0.1*pi); step t y >> H=plot(t,y,'r-o',tt,ye); >> set(H,'LineWidth',3,'MarkerSize',12) >> print -djpeg ode01.jpg

23 Euler’s Method (h = 0.1)

24 Euler’s Method (h = 0.05)

25 Truncation Errors There are
Local truncation errors - error from application at a single step Propagated truncation errors - previous errors carried forward The sum is “global truncation error”

26 Global & Local Errors Global error Local error y y yi+1 yi+1 yi yi o
xi x o xi+1 xi+1 xi+2 x xi

27 Euler’s Method Euler’s method uses Taylor series with only first order terms The true local truncation error is Approximate local truncation error - neglect higher order terms (for sufficiently small h)

28 Runge-Kutta Methods Higher-order Taylor series methods (see Chapra and Canale, 2002) -- need to compute the derivatives of f(t,y) Runge-Kutta Methods -- estimate the slope without evaluating the exact derivatives Heun’s method Midpoint (or improved polygon) method Third-order Runge-Kutta methods Fourth-order Runge-Kutta methods

29 Heun’s Method Improvements of Euler’s method - Heun’s method
Euler’s method - derivative at the beginning of interval is applied to the entire interval Heun’s method uses average derivative for the entire interval A second-order Runge-Kutta Method

30 Heun’s Method Heun’s method is a predictor-corrector method Predictor
Corrector (may be applied iteratively)

31 Heun’s Method Iterate the corrector of Heun’s method to obtain an improved estimate Predictor Corrector

32 Heun’s Method with Iterative Correctors

33 Heun’s Method with Iterative Correctors
» te=0:0.02*pi:pi; ye=example2_e(xe); » [t1,y1]=Euler('example2_f',[0 pi],1,0.1*pi); » [t2,y2]=Heun_iter('example2_f',[0 pi],1,0.1*pi,0); » [t3,y3]=Heun_iter('example2_f',[0 pi],1,0.1*pi,5); » H=plot(te,ye,t1,y1,'r-d',t2,y2,'g-s',t3,y3,'m-o'); » set(H,'LineWidth',3,'MarkerSize',12) » [te' ye' y1',y2',y3'] t yEuler yHeun yHeun_iter ytrue

34 Heun’s Method with Iterative Correctors Heun’s with 5 iterations
Exact Euler’s t

35 Example: Heun’s Method
First Step

36 Example: Heun’s Method
Second Step

37 Example: » [t1,y1]=Eulode('example3',[0 5],1,0.5);
» [t2,y2]=Heun_iter('example3',[0,5],1,0.5,0); » [t3,y3]=Heun_iter('example3',[0 5],1,0.5,5); » [t1' y1' y2' y3' ye'] t yEuler yHeun yHeun_iter ytrue

38 Midpoint Method Improved Polygon or Modified Euler Method
Use the slope at midpoint to represent the average slope

39 Runge-Kutta (RK) Methods
One-Step Method with general form Where  is an increment function which represents the weighted-average slope over the interval Where a’s are constants and k’s are slopes evaluated at selected x locations

40 Runge-Kutta (RK) Methods
One-Step Method General Form of nth-order Runge-Kutta Method Where p’s and q’s are constants k’s are recurrence relationships

41 Second-Order RK Methods
Taylor series expansion Compare to the second-order Taylor formula Three equations for four unknowns (a1, a2, k1, q11)

42 Second-Order RK Methods
Second-order version of Runge-Kutta Methods 3 equations for 4 unknowns

43 Second-Order RK Methods
General Second-order Runge-Kutta methods k2 a1 k1 + a2 k2 k1 Weighted-average slope xi+1 = xi+h xi xi+p1h

44 Use average slope over the interval
Heun’s Method Heun’s method with a single corrector (a2 = 1/2): Choose a2 = 1/2 and solve for the other 3 constants a1 = 1/2, p1 = 1, q11 = 1 Use average slope over the interval

45 Midpoint Method k2 k1 xi xi+1/2 xi+1
Another Second-order Runge-Kutta method Choose a2 = 1  a1 = 0, p1 = 1/2, q11 = 1/2 k2 k1 xi xi+1/2 xi+1

46 Midpoint (2nd-order RK) Method

47 Midpoint (2nd-order RK) Method
>> [t,y] = midpoint('example2_f',[0 pi],1,0.05*pi); step t y >> tt = 0:0.01*pi:pi; yy = example2_e(tt); >> H = plot(t,y,'r-o',tt,yy); >> set(H,'LineWidth',3,'MarkerSize',12);

48 Midpoint (RK2) Method

49 Ralston’s Method Second-order Runge-Kutta method
Choose a2 = 2/3  a1 = 1/3, p1 = q11 = 3/4 k2 k1 k1/3 + 2k2/3 ti xi+1 = ti+h ti+3h/4

50 Third-Order Runge-Kutta Method
General form Weighted slope

51 Third-Order Runge-Kutta Methods
General Third-order Runge-Kutta methods k3 k2 Weighted-average value of three slopes k1 , k2 , k3 k1 ti ti+p1h ti+p2h ti+1 = ti+h

52 Third-order Runge-Kutta Methods
Nystrom Method Nearly Optimum Method

53 3rd-order Runge-Kutta Method
Reduce to Simpson’s 1/3 rule for f = f(t)

54 3rd-Order Heun Method

55 Classical 4th-order Runge-Kutta Method
One-step method Reduce to Simpson’s 1/3 rule for f = f(t)

56 Classical 4th-order Runge-Kutta Method
ti ti + h/2 ti + h

57 Example: Classical 4th-order RK Method
First step, t = 0.5

58 Example: Classical 4th-order RK Method
Second step, t = 1.0

59 Fourth-Order Runge-Kutta Method

60 Fourth-Order Runge-Kutta Method
>> tt=0:0.01*pi:pi; yy=example2_e(tt); >> [t,y]=RK4('example2_f',[0 pi],1,0.05*pi); step t y >> H=plot(x,y,'r-o',xx,yy); >> set(H,'LineWidth',3,'MarkerSize',12);

61 Fourth-Order Runge-Kutta Method

62 Numerical Accuracy h = 0.1 h = 0.05
» tt=0:0.01*pi:pi; yy=example2_e(tt); » t0=0; y0=example2_e(t0); » t1=0.1*pi; y1=example2_e(t1); » [t,ya]=Eulode('example2_f',[0 pi],y0,0.1*pi); » [t,yb]=midpoint('example2_f',[0 pi],y0,y1,0.1*pi); » [t,yc]=Heun_iter('example2_f',[0 pi],y0,0.1*pi,5); » [t,yd]=RK4('example2_f',[0 pi],y0,0.1*pi); » H=plot(t,ya,'m-*',t,yb,'c-d',t,yc,'g-s',t,yd,'r-O',tt,yy); » set(H,'LineWidth',3,'MarkerSize',12); » [t,ya]=Eulode('example2_f',[0 pi],y0,0.05*pi); » [t,yb]=midpoint('example2_f',[0 pi],y0,y1,0.05*pi); » [t,yc]=Heun_iter('example2_f',[0 pi],y0,0.05*pi,5); » [t,yd]=RK4('example2_f',[0 pi],y0,0.05*pi); » print -djpeg075 ode06.jpg h = 0.1 h = 0.05

63 Numerical Accuracy Euler Midpoint Heun (iterative) RK4 h = 0.1

64 Numerical Accuracy Euler Midpoint Heun (iterative) RK4 h = 0.05

65 Butcher’s sixth-order Runge-Kutta Method

66 System of ODEs A system of simultaneous ODEs
n equations with n initial conditions

67 System of ODEs Bungee Jumper’s velocity and position
Two simultaneous ODEs

68 Second-Order ODE Convert to two first-order ODEs

69 System of Two first-order ODEs Euler’s Method
Any method considered earlier can be used Euler’s method for two ODE-IVPs Basic Euler method Two ODE-IVPs

70 Hand Calculations: Euler’s Method
Solve the following ODE from t = 0 to t = 1 with h = 0.5 Euler method

71 Euler’s Method for a System of ODEs
y is a column vector with n variables

72 Euler Method for a System of ODEs
function f = example5(t,y) % dy1/dt = f1 = -0.5 y1 % dy2/dt = f2 = *y *y2 % let y(1) = y1, y(2) = y2 % tspan = [0 1] % initial conditions y0 = [4, 6] f1 = -0.5*y(1); f2 = *y(1) - 0.3*y(2); f = [f1, f2]'; >> [t,y]=Euler_sys('example5',[0 1],[4 6],0.5); t y y y3 ... >> [t,y]=Euler_sys('example5',[0 1],[4 6],0.2); (h = 0.5) (h = 0.2)

73 Euler Method for Second-Order ODE
Nonlinear Pendulum function f = pendulum(t,y) % nonlinear pendulum d^2y/dt^ dy/dt = -sin(y) % convert to two first-order ODEs % dy1/dt = f1 = y2 % dy2/dt = f2 = -0.1*y2 - sin(y1) % let y(1) = y1, y(2) = y2 % tspan = [0 15] % initial conditions y0 = [pi/2, 0] f1 = y(2); f2 = -0.3*y(2) - sin(y(1)); f = [f1, f2]';

74 Euler’s Method for Second-Order ODE
Nonlinear Pendulum » [t,y1]=Euler_sys('pendulum',[0 15],[pi/2 0],15/100); » [t,y2]=Euler_sys('pendulum',[0 15],[pi/2 0],15/200); » [t,y3]=Euler_sys('pendulum',[0 15],[pi/2 0],15/500); » [t,y4]=Euler_sys('pendulum',[0 15],[pi/2 0],15/1000); » H=plot(t1,y1(:,1),t2,y2(:,1),t3,y3(:,1),t4,y4(:,1)) n = 100 n = 200 n = 500 n = 1000

75 Higher Order ODEs In general, nth-order ODE

76 System of First-Order ODE-IVPs
Example Convert to three first-order ODE-IVPs

77 Euler’s Method for Systems of First-Order ODEs
Example

78 Example: Euler’s Method
First step: t(0) = 0, t(1) = 0.5 (h = 0.5) Second step: t(1) = 0.5, t(2) = 1.0

79 Classical 4th-order Runge-Kutta Method for Systems of ODE-IVPs
2 equations Applicable for any number of equations

80 Hand Calculations: RK4 Method
Solve the following ODE from t = 0 to t = 1 with h = 0.5 Classical RK4 method

81 Continued: RK4 Method

82 4th-order Runge-Kutta Method for ODEs
Valid for any number of coupled ODEs

83 4th-order Runge-Kutta Method for ODEs
>> [t,y]=RK4_sys('example5',[0 10],[4 6],0.5); t y y y3 ...

84 4th-order Runge-Kutta Method for ODE-IVPs
Nonlinear Pendulum » tspan=[0 15]; y0=[pi/2 0]; » [t1,y1]=RK4_sys(‘pendulum',tspan,y0,15/25); » [t2,y2]=RK2_sys(‘pendulum',tspan,y0,15/50); » [t3,y3]=RK2_sys(‘pendulum',tspan,y0,15/100); » H=plot(t1,y1(:,1),t2,y2(:,1),t3,y3(:,1)); » set(H,'LineWidth',3.0); n = 25 n = 50 n = 100

85 Comparison of Numerical Accuracy
Nonlinear Pendulum » tspan=[0 15]; y0=[pi/2 0]; » [t1,y1]=Euler_sys(‘pendulum',tspan,y0,15/100); » [t2,y2]=RK2_sys(‘pendulum',tspan,y0,15/100); » [t3,y3]=RK4_sys(‘pendulum',tspan,y0,15/100); » H1=plot(t1,y1(:,1),t2,y2(:,1),t3,y3(:,1)); hold on; » H2=plot(t1,y1(:,2),'b:',t2,y2(:,2),'g:',t3,y3(:,2),'r:'); Euler RK2 RK4  

86 Example: More than 2 ODE-IVPs
function f = example(t, y) % solve y' = Ay = f, y0 = [ ]' % four first-order ODE-IVPs A = [ ]; y=[ y(1) y(2) y(3) y(4)]'; f = A*y;

87 4th-order Runge-Kutta Method for ODE-IVPs
Symbols: n = 20 Lines : n =100 » tspan=[0 2]; y0=[ ]; » [t1,y1]=RK4_sys(‘example', tspan, y0, 2/20); » [t2,y2]=RK4_sys(‘example', tspan, y0, 2/100); » H1=plot(t1,y1,'o'); set(H1,'LineWidth',3','MarkerSize',12); » hold on; H2=plot(t2,y2); set(H2,'LineWidth',3);

88 CVEN 302-501 Homework No. 13 Chapter 20
Prob (40), (Hand Calculation, and use MATLAB plotting for graph) 20.3 a) , b) and c) (40)(Hand Calculation) Prob (30) (decomposing into two 1st ODEs and then using MATLAB Program) Due on Wed. 11/26/2008 at the beginning of the period


Download ppt "ODEs: Initial-Value Problems"

Similar presentations


Ads by Google