lecture 5 polynomial approximation

Post on 12-Jan-2016

51 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Lecture 5 Polynomial Approximation. Polynomial Interpolation Example Limitation Polynomial Approximation (fitting) Line fitting Quadratic curve fitting Polynomial fitting. Polynomials. Polynomial determined by zeros in [-4,0,3]. P=poly([-4 0 3]);. Plot polynomial P. x=linspace(-5,5); - PowerPoint PPT Presentation

TRANSCRIPT

數值方法 1

Polynomial InterpolationExampleLimitation

Polynomial Approximation (fitting)Line fittingQuadratic curve fittingPolynomial fitting

Lecture 5 Polynomial Lecture 5 Polynomial ApproximationApproximation

數值方法 2

PolynomialsPolynomials

P=poly([-4 0 3]); Polynomial determined byzeros in [-4,0,3]

x=linspace(-5,5);y=polyval(P,x);plot(x,y);

Plot polynomial P

數值方法 3

Sampling of paired dataSampling of paired data

P=poly([-4 0 3]); Produce a polynomialwith zeros [-4,0,3]

x=rand(1,6)*10-5;y=polyval(P,x);plot(x,y, 'ro');

Plot paired data

數值方法 4

Polynomial interpolationPolynomial interpolation

P=poly([-4 0 3]); n=6Produce a polynomialwith zeros [-4,0,3]

x=rand(1,n)*10-5;y=polyval(P,x);plot(x,y, 'ro');

Plot the interpolating polynomial

v=linspace(min(x),max(x));z=int_poly(v,x,y);plot(v,z,'k');

數值方法 5

Source codes

Demo_ipDemo_ip

數值方法 6

m=3, n=5m=3, n=5

>> demo_ipdata size n=5

數值方法 7

m=3, n=6m=3, n=6

>> demo_ipdata size n=6

數值方法 8

m=3, n=10m=3, n=10

>> demo_ipdata size n=10

數值方法 9

>> demo_ipdata size n=12

m=3, n=12m=3, n=12

數值方法 10

P=poly([-4 0 3]);n=6; Produce a polynomialwith zeros [-4,0,3]

x=rand(1,n)*10-5;y=polyval(P,x);nois=rand(1,n)*0.5-0.25;plot(x,y+nois, 'ro');

Plot the interpolating polynomial

v=linspace(min(x),max(x));z=int_poly(v,x,y+nois);plot(v,z,'k');

Sample with noiseSample with noise

數值方法 11

Demo_ip_noisyDemo_ip_noisy

source codes

數值方法 12

Noise dataNoise data

►Noise ratioNoise ratio Mean of abs(noise)/abs(signal) Mean of abs(noise)/abs(signal)

noise_ratio =

0.0074

數值方法 13

Numerical resultsNumerical results

Small noise causes intolerant interpolation

>> demo_ip_noisydata size n:12

noise_ratio =

0.0053

數值方法 14

Numerical resultsNumerical results

Small noise causes intolerant interpolation

>> demo_ip_noisydata size n:13

noise_ratio =

0.0031

數值方法 15

Interpolation Vs Interpolation Vs approximationapproximation

► An interpolating polynomial is expected to satisfy An interpolating polynomial is expected to satisfy all constraints posed by paired dataall constraints posed by paired data

► An interpolating polynomial is unable to retrieve an An interpolating polynomial is unable to retrieve an original target function when noisy paired data are original target function when noisy paired data are provided provided

► For noisy paired data, the goal of polynomial fitting For noisy paired data, the goal of polynomial fitting is revised to minimize the mean square is revised to minimize the mean square approximating errorapproximating error

數值方法 16

Polynomial approximationPolynomial approximation

►Given paired data, (xGiven paired data, (xii,y,yii), i=1,…,n,), i=1,…,n,

the approximating polynomial is the approximating polynomial is required to minimize the mean required to minimize the mean square error of approximating ysquare error of approximating yi i by by f(xf(xii))

2

1

))((1

E

n

iii yxf

n

數值方法 17

Polynomial fittingPolynomial fitting

fa1d_polyfit.m

數值方法 18

Line fittingLine fitting

►Minimizaing the mean square Minimizaing the mean square approximating errorapproximating error

2

1

)(1

b)E(a,

n

iii ybax

n

Target: baxy

數值方法 19

Line fittingLine fitting

Red:Approximating polynomial

>> fa1d_polyfitinput a function: x.^2+cos(x) :x+5keyin sample size:300polynomial degree:1

E =

8.3252e-004

a=1;b=5

數值方法 20

Line fittingLine fitting

Red:Approximating polynomial

a=3;b=1/2

>> fa1d_polyfitinput a function: x.^2+cos(x) :3*x+1/2keyin sample size:30polynomial degree:1

E =

0.0010

數值方法 21

Objective function IObjective function I

►Line fitting Line fitting

2

1fitting-Line1 )(

1b)(a,E)(E

n

iii ybax

n

Target: baxy

數值方法 22

►EE1 1 is a quadratic function of a and bis a quadratic function of a and b

►Setting derivatives of ESetting derivatives of E1 1 to zero to zero leads to leads to

a linear systema linear system 2

1fitting-Line1 )(

1b)(a,E)(E

n

iii ybax

n

數值方法 23

0)(2

0)(2

0

)(1

b)(a,E)(E

1

1

1

1

1

2

1fitting-Line1

n

iii

i

n

iii

n

iii

ybaxndb

dE

xybaxnda

dEd

dE

ybaxn

a linear system

數值方法 24

n

ii

n

ii

n

iii

n

ii

n

ii

n

iii

n

iiiii

n

iii

i

n

iii

ynbax

yxbxax

ybax

xybxax

ybaxndb

dE

xybaxnda

dE

11

111

2

1

1

2

1

1

1

1

0)(

0)(

0)(2

0)(2

數值方法 25

n

ii

n

iii

n

ii

n

ii

n

ii

n

ii

n

ii

n

iii

n

ii

n

ii

y

yx

b

a

nx

xx

ynbax

yxbxax

1

1

1

11

2

11

111

2

數值方法 26

n

ii

n

iii

n

ii

n

ii

n

ii

n

ii

n

iii

n

ii

n

ii

n

ii

y

yx

nx

xx

b

a

y

yx

b

a

nx

xx

1

1

1

1

11

2

1

1

1

11

2

數值方法 27

Objective function IIObjective function II

►Quadratic polynomial fittingQuadratic polynomial fitting

2

1

2

gurveFittinQuadraticC2

)(1

c)b,(a,E)(E

n

iiii ycbxax

n

Target: cbxaxy 2

數值方法 28

►EE2 2 are quadraticare quadratic

►Setting derivatives of ESetting derivatives of E2 2 to zero to zero leads to leads to

a linear systema linear system

2

1

2

gurveFittinQuadraticC2

)(1

c)b,(a,E)(E

n

iiii ycbxax

n

數值方法 29

0)(2

0)(2

0)(2

0

)(1

c)b,(a,E)(E

1

23

1

22

2

1

22

2

2

1

2gurveFittinQuadraticC2

n

iiii

i

n

iiii

i

n

iiii

n

iiii

ycbxaxndc

dE

xycbxaxndb

dE

xycbxaxnda

dEd

dE

ycbxaxn

a linear system

數值方法 30

0)(

0)(

0)(

1

2

1

2

2

1

2

n

iiii

i

n

iiii

i

n

iiii

ycbxax

xycbxax

xycbxax

0)(

0)(

0)(

1

2

1

23

1

2234

n

iiii

n

iiiiii

n

iiiiii

ycbxax

xycxbxax

xycxbxaxˋ

數值方法 31

0)(

0)(

0)(

1

2

1

23

1

2234

n

iiii

n

iiiiii

n

iiiiii

ycbxax

xycxbxax

xycxbxaxˋ

n

ii

n

ii

n

ii

n

iii

n

ii

n

ii

n

ii

n

iii

n

ii

n

ii

n

ii

yncbxax

xycxbxax

xycxbxax

111

2

111

2

1

3

1

2

1

2

1

3

1

4

數值方法 32

n

ii

n

ii

n

ii

n

iii

n

ii

n

ii

n

ii

n

iii

n

ii

n

ii

n

ii

yncbxax

xycxbxax

xycxbxax

111

2

111

2

1

3

1

2

1

2

1

3

1

4

n

ii

n

iii

n

iii

n

ii

n

ii

n

ii

n

ii

n

ii

n

ii

n

ii

n

ii

y

xy

xy

c

b

a

nxx

xxx

xxx

1

1

1

2

11

2

11

2

1

3

1

2

1

3

1

4

數值方法 33

Quadratic polynomial Quadratic polynomial fittingfitting

►Minimization of an approximating Minimization of an approximating errorerror

2

1

2 )(1

c)b,E(a,

n

iiii ycbxax

n

Target: cbxaxy 2

數值方法 34

Quadratic poly fittingQuadratic poly fitting

input a function: x.^2+cos(x) :3*x.^2-2*x+1keyin sample size:20polynomial degree:2

E =

6.7774e-004a=3b=-2c=1

數值方法 35

Data driven polynomial Data driven polynomial approximationapproximation

►Minimization of Mean square error Minimization of Mean square error (mse)(mse)

►Data driven polynomial Data driven polynomial approximationapproximation f : a polynomial pf : a polynomial pmm

Polynomial degree m is less than data Polynomial degree m is less than data size nsize n

2

1

))((1

E

n

iiim yxp

n

數值方法 36

i allfor )( 0E

))((1

E 2

1

imi

n

iiim

xpy

yxpn

Special case: polynomial Special case: polynomial interpolationinterpolation

數值方法 37

POLYFIT: Fit polynomial to dataPOLYFIT: Fit polynomial to data

►polyfit(x,y,m)polyfit(x,y,m) x : input vectors or predictorsx : input vectors or predictors y : desired outputsy : desired outputs m : degree of interpolating polynomialm : degree of interpolating polynomial

►Use m to prevent from over-fittingUse m to prevent from over-fitting►Tolerance to noiseTolerance to noise

數值方法 38

POLYFIT: Fit polynomial to POLYFIT: Fit polynomial to datadata

P=poly([-4 0 3]); n=20;m=3; A polynomial determinedby zeros in [-4,0,3]

x=rand(1,20)*10-5;y=polyval(P,x);nois=rand(1,20)*0.5-0.25;plot(x,y+nois, 'ro');

Plot the interpolating polynomial

v=linspace(min(x),max(x));p=polyfit(x,y+nois,m);hold on;plot(v,polyval(p,v),'k');

數值方法 39

Non-polynomialNon-polynomial

► sinsin

fx=inline('sin(x)'); n=20;m=3

x=rand(1,n)*10-5;y=fx(x);nois=rand(1,n)*0.5-0.25;plot(x,y+nois, 'ro');hold on

數值方法 40

Under-fittingUnder-fitting

v=linspace(min(x),max(x));p=polyfit(x,y+nois,m);hold on;plot(v,polyval(p,v),'k');

m=3

Under-fitting due to approximating non-polynomial by low-degree polynomials

數值方法 41

Intolerant mseIntolerant mse

>> mean((polyval(p,x)-(y+nois)).^2)

ans =

0.0898

Under-fitting causes intolerant mean square error

數值方法 42

m=4;v=linspace(min(x),max(x));p=polyfit(x,y+nois,m);hold on;plot(v,polyval(p,v), 'b');

Under-fittingUnder-fitting

M=4

數值方法 43

>> fa1d_polyfitinput a function: x.^2+cos(x) :sin(x)keyin sample size:50polynomial degree:5

E =

0.0365

Fitting non-polynomialFitting non-polynomial

數值方法 44

>> fa1d_polyfitinput a function: x.^2+cos(x) :tanh(x+2)+sech(x)keyin sample size:30polynomial degree:5

E =

0.0097

Fitting non-polynomialFitting non-polynomial

top related