Numerical Differentiation 2008 Applied Mathematics NDHU 1 Composite

  • Slides: 26
Download presentation
Numerical Differentiation 數值方法 2008, Applied Mathematics NDHU 1

Numerical Differentiation 數值方法 2008, Applied Mathematics NDHU 1

Composite Simpson rule h=(b-a)/2 n Simpson's Rule for Numerical Integration 數值方法 2008, Applied Mathematics

Composite Simpson rule h=(b-a)/2 n Simpson's Rule for Numerical Integration 數值方法 2008, Applied Mathematics NDHU 2

A procedure for CSR ► ► ► function Q=CSR(fs, a, b, n) fx=inline(fs); h=(b-a)/(2*n);

A procedure for CSR ► ► ► function Q=CSR(fs, a, b, n) fx=inline(fs); h=(b-a)/(2*n); ind=0: 1: 2*n; Q=fx(a)+fx(b); % Red ind_odd=1: 2: (2*n-1); % white ind_even=2: 2: 2*(n-1); Q=Q+sum(4*fx(a+ind_odd*h)); Q=Q+sum(2*fx(a+ind_even*h)); Q=Q/3*h; 數值方法 2008, Applied Mathematics NDHU 3

Symbolic Differentiation demo_diff. m 數值方法 2008, Applied Mathematics NDHU 4

Symbolic Differentiation demo_diff. m 數值方法 2008, Applied Mathematics NDHU 4

Example function of x: tanh(x) fx 1 = Inline function: fx 1(x) = 1

Example function of x: tanh(x) fx 1 = Inline function: fx 1(x) = 1 -tanh(x). ^2 數值方法 2008, Applied Mathematics NDHU 5

Numerical differentiation 數值方法 2008, Applied Mathematics NDHU 6

Numerical differentiation 數值方法 2008, Applied Mathematics NDHU 6

Truncation error The truncation error linearly depends on h 數值方法 2008, Applied Mathematics NDHU

Truncation error The truncation error linearly depends on h 數值方法 2008, Applied Mathematics NDHU 7

Better approximation 數值方法 2008, Applied Mathematics NDHU 8

Better approximation 數值方法 2008, Applied Mathematics NDHU 8

Truncation error O(h 2) : big order of h square The truncation error linearly

Truncation error O(h 2) : big order of h square The truncation error linearly depends on h 2 數值方法 2008, Applied Mathematics NDHU 9

Richardson extrapolation is with O(h 3) Start at the formula that is with O(h

Richardson extrapolation is with O(h 3) Start at the formula that is with O(h 2) Strategy: elimination of h 2 term 數值方法 2008, Applied Mathematics NDHU 10

Halving step-size 數值方法 2008, Applied Mathematics NDHU 11

Halving step-size 數值方法 2008, Applied Mathematics NDHU 11

Richardson extrapolation 數值方法 2008, Applied Mathematics NDHU 12

Richardson extrapolation 數值方法 2008, Applied Mathematics NDHU 12

Richardson extrapolation 數值方法 2008, Applied Mathematics NDHU 13

Richardson extrapolation 數值方法 2008, Applied Mathematics NDHU 13

Demo_Richardson demo_Richardson. m 數值方法 2008, Applied Mathematics NDHU 14

Demo_Richardson demo_Richardson. m 數值方法 2008, Applied Mathematics NDHU 14

Example >>demo_Richardson function of x: sin(x) fx 1 = Inline function: fx 1(x) =

Example >>demo_Richardson function of x: sin(x) fx 1 = Inline function: fx 1(x) = cos(x) h: 0. 01 數值方法 2008, Applied Mathematics NDHU 15

Example: differentiation of sin [-5 5] h=0. 01 數值方法 2008, Applied Mathematics NDHU 16

Example: differentiation of sin [-5 5] h=0. 01 數值方法 2008, Applied Mathematics NDHU 16

Exercise Due to 12/26 ► Implement the Richardson extrapolation method for numerical differentiation ►

Exercise Due to 12/26 ► Implement the Richardson extrapolation method for numerical differentiation ► Give two examples to verify your matlab functions for Richardson extrapolation implementation 數值方法 2008, Applied Mathematics NDHU 17

Line fitting 數值方法 2008, Applied Mathematics NDHU 18

Line fitting 數值方法 2008, Applied Mathematics NDHU 18

Problem statement ► S={(ui vi)}i ► Find a line to fit a set of

Problem statement ► S={(ui vi)}i ► Find a line to fit a set of 2 D points, 數值方法 2008, Applied Mathematics NDHU 19

Paired data m=100; u=rand(1, m); v=1. 5*u+2+rand(1, m)*0. 1 -0. 05; plot(u, v, '.

Paired data m=100; u=rand(1, m); v=1. 5*u+2+rand(1, m)*0. 1 -0. 05; plot(u, v, '. ') 數值方法 2008, Applied Mathematics NDHU 20

Linear model 數值方法 2008, Applied Mathematics NDHU 21

Linear model 數值方法 2008, Applied Mathematics NDHU 21

Over-determined Linear system 數值方法 2008, Applied Mathematics NDHU 22

Over-determined Linear system 數值方法 2008, Applied Mathematics NDHU 22

Form A and b A=[u' ones(100, 1)]; b=v'; 數值方法 2008, Applied Mathematics NDHU 23

Form A and b A=[u' ones(100, 1)]; b=v'; 數值方法 2008, Applied Mathematics NDHU 23

Line fitting >> x=inv(A'*A)*A'*b x= 1. 4816 2. 0113 數值方法 2008, Applied Mathematics NDHU

Line fitting >> x=inv(A'*A)*A'*b x= 1. 4816 2. 0113 數值方法 2008, Applied Mathematics NDHU 24

Demo_line_fitting demo_line_fitting. m 數值方法 2008, Applied Mathematics NDHU 25

Demo_line_fitting demo_line_fitting. m 數值方法 2008, Applied Mathematics NDHU 25

Stand alone executable file mcc -m demo_line_fitting. m 數值方法 2008, Applied Mathematics NDHU 26

Stand alone executable file mcc -m demo_line_fitting. m 數值方法 2008, Applied Mathematics NDHU 26