王俊鑫 (Chun-Hsin Wang) 中華大學 資訊工程系 Fall 2002 Chap 2 Numerical Methods for First-Order Differential Equations
Page 2 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
Page 3 Direction Field General Forms for First-Order ODE Implicit Form Explicit Form
Page 4 Direction Field dfield is an interactive tool for studying single first order differential equations. Written in MATLAB by John C. Polking (java version)
Page 5 Starting Difeld Tool
Page 6 Direction Field Methods Using dfield tool
Page 7 Direction Field Using Dfield
Page 8 Print Direction Field Using dfield
Page 9 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
Page 10 Plot a particular solution
Page 11 Plot a particular solution
Page 12 Plot a particular solution
Page 13 Enter Text Annotation
Page 14 Enter Text Annotation
Page 15
Page 16 Direction Field Methods Exercise 2-1: Plot the particular solutions for the following ODEs and initial conditions using dfield
Page 17
Page 18 Numerical Approximation To numerically “solve” y = f(x, y) with y(a) = y 0 on the interval [a, b], we find a discrete set of points a = x 0 < x 1 < x 2 < · · · < x N-1 < x N = b and values y 0, y 1, y 2,..., y N-1, y N with y j approximately equal to y(x j ). Making an error E j = y(x j ) - y j
Page 19 Euler, Léonard
Page 20 Euler’s Method Problem: Solve ( approximately ) y = f(x, y) with y(a) = y 0 on the interval [a, b]. Discrete set of values x 0 = a, fixed step size h = (b - a)/N x 1 = x 0 + h, x 2 = x 1 + h = x 0 + 2h, etc, x N = a + Nh = b
Page 21 Euler’s Method At each step approximate the solution curve by the tangent line.
Page 22 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.
Page 23 Euler’s Method Local Error Taylor Series Euler’s Method Local Error = Taylor Series - Euler’s Method
Page 24 Euler’s Method Local Error
Page 25 Euler’s Method Exercise 2-3: Sol: Note: Exact Solution
Page 26 Euler’s Method Cumulative Error
Page 27 Euler’s Method Cumulative Error (Global Error)
Page 28 Euler’s Method Cumulative Error
Page 29 Euler’s Method Cumulative Error
Page 30 Euler’s Method MATLAB Code
Page 31 Heun’s Method Also called Improved Euler’s Method Euler’s Method Heun’s Method (Based on Trapezoid Rule)
Page 32 Heun’s Method Average Slope
Page 33 Heun’s Method Example 2-4
Page 34 Heun’s Method MATLAB Code
Page 35 Runge-Kutta Methods Runge-Kutta Method is more accurate than Heun’s Method Developed by two German mathematicians Carl Runge ( ) Wilhelm Kutta ( )
Page 36 Runge-Kutta vs Euler Both use a fixed step size h = (b - a)/N. Euler’s method Y n+1 = y n + f(x n, y n ) h Runge-Kutta methods Y n+1 = y n + S · h S is a weighted average of two or more slopes. Slopes chosen to increase the accuracy.
Page 37 Runge-Kutta Methods 積分定義 泰勒展開式 Trapezoid Rule Trapezoid Rule Simpson’s Rule Simpson’s Rule 二項展開 四項展開 Runge-Kutta Order 2 Runge-Kutta Order 2 Runge-Kutta Order 4 Runge-Kutta Order 4
Page 38 Runge-Kutta Method of Order 2
Page 39 Runge-Kutta Method of Order 2 Example 2-5
Page 40 Runge-Kutta Method of Order 4 Simpson’s Rule
Page 41 Runge-Kutta Method of Order 4
Page 42 Runge-Kutta Method of Order 4 Example 2-6
Page 43 Runge-Kutta Method of Order 4 MATLAB Code
Page 44 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, Shampine, L. F., Numerical Solution of Ordinary Differential Equations, Chapman & Hall, New York, 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.