數值方法 2008, applied mathematics ndhu 1 numerical differentiation

Post on 18-Jan-2018

229 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

數值方法 2008, Applied Mathematics NDHU 3 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;

TRANSCRIPT

數值方法2008, Applied Mathematics NDHU 1

Numerical Differentiation

數值方法2008, Applied Mathematics NDHU 2

Composite Simpson ruleComposite Simpson ruleh=(b-a)/2nh=(b-a)/2n

Simpson's Rule for Numerical Integration

數值方法2008, Applied Mathematics NDHU 3

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

數值方法2008, Applied Mathematics NDHU 4

Symbolic DifferentiationSymbolic Differentiation

demo_diff.m

數值方法2008, Applied Mathematics NDHU 5

ExampleExample

-5 -4 -3 -2 -1 0 1 2 3 4 5-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

function of x:tanh(x)

fx1 =

Inline function: fx1(x) = 1-tanh(x).^2

數值方法2008, Applied Mathematics NDHU 6

Numerical differentiationNumerical differentiation

數值方法2008, Applied Mathematics NDHU 7

Truncation error Truncation error

The truncation error linearly depends on h

數值方法2008, Applied Mathematics NDHU 8

Better approximationBetter approximation

數值方法2008, Applied Mathematics NDHU 9

Truncation errorTruncation error

O(h2) : big order of h square The truncation error linearly depends on h2

數值方法2008, Applied Mathematics NDHU 10

Richardson extrapolationRichardson extrapolationRichardson extrapolation is with O(h3)Start at the formula that is with O(h2)

Strategy: elimination of h2 term

數值方法2008, Applied Mathematics NDHU 11

Halving step-sizeHalving step-size

數值方法2008, Applied Mathematics NDHU 12

Richardson extrapolationRichardson extrapolation

數值方法2008, Applied Mathematics NDHU 13

Richardson extrapolationRichardson extrapolation

數值方法2008, Applied Mathematics NDHU 14

Demo_RichardsonDemo_Richardsondemo_Richardson.m

數值方法2008, Applied Mathematics NDHU 15

ExampleExample>>demo_Richardsonfunction of x:sin(x)

fx1 =

Inline function: fx1(x) = cos(x)

h:0.01

數值方法2008, Applied Mathematics NDHU 16

Example: differentiation of Example: differentiation of sinsin

[-5 5]h=0.01

-5 -4 -3 -2 -1 0 1 2 3 4 5-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

數值方法2008, Applied Mathematics NDHU 17

ExerciseExerciseDue to 12/26Due to 12/26

► Implement the Richardson Implement the Richardson extrapolation method for numerical extrapolation method for numerical differentiationdifferentiation

►Give two examples to verify your Give two examples to verify your matlab functions for Richardson matlab functions for Richardson extrapolation implementationextrapolation implementation

數值方法2008, Applied Mathematics NDHU 18

Line fittingLine fitting

數值方法2008, Applied Mathematics NDHU 19

Problem statementProblem statement►S={(uS={(ui i vvii)})}ii

►Find a line to fit a set of 2D points,Find a line to fit a set of 2D points,

數值方法2008, Applied Mathematics NDHU 20

Paired dataPaired data

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 11.8

2

2.2

2.4

2.6

2.8

3

3.2

3.4

3.6

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 21

Linear modelLinear model

數值方法2008, Applied Mathematics NDHU 22

Over-determined Linear Over-determined Linear systemsystem

數值方法2008, Applied Mathematics NDHU 23

Form A and bForm A and b

A=[u' ones(100,1)];b=v';

ii

i

vbu

1] [ia

數值方法2008, Applied Mathematics NDHU 24

Line fittingLine fitting

>> x=inv(A'*A)*A'*b

x =

1.4816 2.0113

數值方法2008, Applied Mathematics NDHU 25

Demo_line_fittingDemo_line_fittingdemo_line_fitting.m

數值方法2008, Applied Mathematics NDHU 26

Stand alone executable fileStand alone executable file

mcc -m demo_line_fitting.m

top related