470 likes | 948 Views
Chap 2 Numerical Methods for First-Order Differential Equations . 王俊鑫 ( Chun-Hsin Wang) 中華大學 資訊工程系 Fall 2002. Outline. Direction Field Methods Using dfield (MATLAB / java) Euler’s Method Heun’s Method Runge-Kutta Method of Order 2 Runge-Kutta Method of Order 4. Direction Field.
E N D
Chap 2 Numerical Methods for First-Order Differential Equations 王俊鑫 (Chun-Hsin Wang) 中華大學 資訊工程系 Fall 2002
Outline • Direction Field Methods Using dfield (MATLAB / java) • Euler’s Method • Heun’s Method • Runge-Kutta Method of Order 2 • Runge-Kutta Method of Order 4
Direction Field • General Forms for First-Order ODE • Implicit Form • Explicit Form
Direction Field • dfield is an interactive tool for studying single first order differential equations. • Written in MATLAB by John C. Polking • http://math.rice.edu/~polking/ • http://math.rice.edu/~dfield/dfpp.html (java version)
Pint The Direction Field • Use the print screen function key (PtrSc) to save the picture of your computer screen into the clipboard automatically. • Paste the picture to a graphic tool (ex. 小畫家) • Use the graph tool to cut the direction field you want • Paste the direction field to a new file and then print it • Note : verify your picture by using print review
Direction Field Methods • Exercise 2-1: Plot the particular solutions for the following ODEs and initial conditions using dfield
Numerical Approximation • To numerically “solve” y= f(x, y) with y(a) = y0on the interval [a, b], we find • a discrete set of points a = x0< x1< x2< · · · < xN-1< xN= b • and values y0, y1, y2, . . . , yN-1, yN with yjapproximately equal to y(xj). • Making an error Ej= y(xj) - yj
Euler, Léonard Euler, Léonard 1707-1783
Euler’s Method • Problem: Solve ( approximately ) y= f(x, y) with y(a) = y0 on the interval [a, b]. • Discrete set of values • x0= a, fixed step size h = (b -a)/N • x1= x0+ h, x2= x1+ h = x0+ 2h, etc, • xN= a + Nh = b
Euler’s Method • At each step approximate the solution curve by the tangent line.
Euler’s Method • Euler’s Method solves the first order differential equation y' = f(x,y) by a simple stepping procedure using the first two terms of a Taylor expansion of the function y(x). • Also called Taylor Series Method(of order 1) or Stepping Method.
Euler’s Method • Local Error Taylor Series Euler’s Method Local Error = Taylor Series - Euler’s Method
Euler’s Method • Local Error
Euler’s Method • Exercise 2-3: Sol: Note: Exact Solution
Euler’s Method • Cumulative Error
Euler’s Method • Cumulative Error (Global Error)
Euler’s Method • Cumulative Error
Euler’s Method • Cumulative Error
Euler’s Method • MATLAB Code
Heun’s Method • Also called Improved Euler’s Method Euler’s Method Heun’s Method (Based on Trapezoid Rule)
Heun’s Method • Average Slope
Heun’s Method • Example 2-4
Heun’s Method • MATLAB Code
Runge-Kutta Methods • Runge-Kutta Method is more accurate than Heun’s Method • Developed by two German mathematicians • Carl Runge (1856-1927) • Wilhelm Kutta (1867-1944)
Runge-Kutta vs Euler • Both use a fixed step size h = (b - a)/N. • Euler’s method • Yn+1= yn+ f(xn, yn)h • Runge-Kutta methods • Yn+1= yn+ S · h • S is a weighted average of two or more slopes. • Slopes chosen to increase the accuracy.
Runge-Kutta Methods 積分定義 泰勒展開式 Trapezoid Rule Simpson’s Rule 二項展開 四項展開 Runge-Kutta Order 2 Runge-Kutta Order 4
Runge-Kutta Method of Order 2 • Example 2-5
Runge-Kutta Method of Order 4 Simpson’s Rule
Runge-Kutta Method of Order 4 • Example 2-6
Runge-Kutta Method of Order 4 • MATLAB Code
References • Dormand, J. R. and P. J. Prince, “A family of embedded Runge-Kutta formulae,” J. Comp. Appl. Math., Vol. 6, 1980, pp 19–26. • Bogacki, P. and L. F. Shampine, “A 3(2) pair of Runge-Kutta formulas,” Appl. Math. Letters, Vol. 2, 1989, pp 1–9. • Kahaner, D. , C. Moler, and S. Nash, Numerical Methods and Software, Prentice-Hall, New Jersey, 1989. • Shampine, L. F. , Numerical Solution of Ordinary Differential Equations, Chapman & Hall, New York, 1994. • Shampine, L. F. and M. W. Reichelt, “The MATLAB ODE Suite,” (to appear in SIAM Journal on Scientific Computing, Vol. 18-1, 1997). • Shampine, L. F. and M. E. Hosea, “Analysis and Implementation of TR-BDF2,” Applied Numerical Mathematics 20, 1996.