Download Wavelet / TCQ Image Compression

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
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
Page 2
Direction Field

General Forms for First-Order ODE

Implicit Form
F ( x, y , y )  0

Explicit Form
y   f ( x, y )
Page 3
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)
Page 4
Starting Difeld Tool
Page 5
Direction Field Methods Using
dfield tool
Page 6
Direction Field Using Dfield
Page 7

Print Direction Field Using dfield
Page 8
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 9
Plot a particular solution
Page 10
Plot a particular solution
Page 11
Plot a particular solution
Page 12
Enter Text Annotation
Page 13
Enter Text Annotation
Page 14
Page 15
Direction Field Methods

Exercise 2-1: Plot the particular solutions for the
following ODEs and initial conditions using dfield
x  2t , x (0)  4
x  2 x, x (0)  2
x   t / x , x ( 2 ) 
2
x  x  t , x (0)  0
Page 16
Page 17
Numerical Approximation

To numerically “solve” y = f(x, y)
with y(a) = y0 on 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 yj approximately equal to y(xj).
 Making an error Ej = y(xj) - yj

Page 18
Euler, Léonard
Euler, Léonard
1707-1783
Page 19
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
Page 20
Euler’s Method

At each step approximate the solution
curve by the tangent line.
y( x0  h)  y( x0 )  y' ( x0 )h, x1  x0  h
y( x1 )  y0  f ( x0 , y0 )h
Set
so
y1  y0  f ( x0 , y0 )h,
y ( x1 )  y1
Page 21
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 22
Euler’s Method

Local Error
Taylor Series
2!
3!
y( x  h)  y( x)  h  y' ( x) 
h 2  y ( x ) 
h 3  y ( x )  
1
1
Euler’s Method
yn 1  yn  h  yn  yn  h  f ( xn , yn )
Local Error = Taylor Series - Euler’s Method
2!
3!
m!
n
n
Local Error 
h 2  y  
h 3  y    
h m  yn( m )  
1
1
1
Page 23
Euler’s Method

Local Error
Page 24
Euler’s Method

Exercise 2-3:
y   x  y , y (0)  1, n  10, Find y (1)
Sol:
y1  1.0000  0.1  (0.0  1.0000)  1.1000
y2  1.1000  0.1  (0.1  1.1000)  1.2200
y3  1.2200  0.1  (0.2  1.2200)  1.3620

Note: Exact Solution
y ( x )  2e x  x  1
Page 25
Euler’s Method

Cumulative Error
Page 26
Euler’s Method

Cumulative Error (Global Error)
Page 27
Euler’s Method

Cumulative Error
Page 28
Euler’s Method

Cumulative Error
Page 29
Euler’s Method

MATLAB Code
Page 30
Heun’s Method

Also called Improved Euler’s Method
k1  f ( xn , yn )
un 1  yn  h  k1
k2  f ( xn  h,
yn  1
Euler’s Method
un 1 )
h
k1  k2 
 yn 
2
Heun’s Method
(Based on Trapezoid Rule)
Page 31
Heun’s Method

Average Slope
Page 32
Heun’s Method

Example 2-4
Page 33
Heun’s Method

MATLAB Code
Page 34
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)
Page 35
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.
Page 36
Runge-Kutta Methods
積分定義
Trapezoid
Rule
Simpson’s
Rule
Runge-Kutta
Order 2
泰勒展開式
二項展開
四項展開
Runge-Kutta
Order 4
Page 37
Runge-Kutta Method of Order 2
y   f ( x, y )
y ( xn  1 )  y ( xn ) 

xn  1
xn
y ( xn 1 )  y ( xn ) 

x n 1
xn
y ( x )dx
f ( x, y )dx
h ( f ( xn , yn )  f ( xn  1 , yn  1 ))
, Trapezoid Rule
2
1

( K1  K 2 )
2

K1  h  f ( xn , yn )
K2  h  f ( xn  h,
yn  K1 )
Page 38
Runge-Kutta Method of Order 2

Example 2-5 y  x  y, y (0)  1, n  2, y (1)  ?
dX
x
yn
Round 1
0.5
0
1
Round 2
0.5
0.5
1.75
K1
0.5(0+1)=0.5
0.5*(0.5+1.75)=1.125
K2
yn+1
0.5*(0+0.5+1+0.5)=1 0.5*(0.5+0.5+1.75+1.125)=1.9375
1+(0.5+1)/2=1.75
1.75+(1.125+1.9375)/2=3.28125
Page 39
Runge-Kutta Method of Order 4
y   f ( x, y )
y ( xn  1 )  y ( xn ) 

xn  1
y ( xn 1 )  y ( xn ) 

x n 1
xn
y ( x )dx
f ( x, y )dx
Simpson’s Rule
x  xn y n  1  y n


h  f ( xn , y n )  4 f ( n  1
,
)  f ( xn  1 , y n  1 ) 
2
2

 
6
1
 ( K1  2 K 2  2 K3  K 4 )
6
xn
Page 40
Runge-Kutta Method of Order 4
K1  h  f ( xn , yn )
K2
h
K1
 h  f ( xn 
, yn 
)
2
2
K3
h
K2
 h  f ( xn 
, yn 
)
2
2
K4  h  f ( xn  h,
yn  K3 )
Page 41
Runge-Kutta Method of Order 4

Example 2-6
Page 42
Runge-Kutta Method of Order 4

MATLAB Code
Page 43
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 TRBDF2,” Applied Numerical Mathematics 20, 1996.
Page 44
Related documents