Presentation is loading. Please wait.

Presentation is loading. Please wait.

Curve fitting with polyfit

Similar presentations


Presentation on theme: "Curve fitting with polyfit"— Presentation transcript:

1 Curve fitting with polyfit
noise=randn(1,30); x=1:1:30; y=x+noise y = [p,s]=polyfit(x,y,1) p = s = R: [2x2 double] df: 28 normr: yfit=polyval(p,x); plot(x,y,'+',x,x,'r',x,yfit,'b')

2 Comparison with data and fit shown in class
From class: p= Now: p =

3 Wrong function rather than noise
yq=x+0.01*x.^ >> [p,s]=polyfit(x,yq,1) p = s = R: [2x2 double] df: 28 normr: yqfit=polyval(p,x); plot(x,yq,'+',x,yqfit,'r') .

4 Using regress instead (noisy data)
xx=[ones(30,1),x']; [b,bint]=regress(y',xx) b = bint = [b,bint,r,rint,stats] = regress(y',xx); stats stats =(R,the F statistic and its p value, estimate of the error variance.) 1.0e+03 * sighat=sqrt(stats(4)) =1.0334

5 Residuals and cross validation errors
xprimex=xx'*xx xprimex = E=xx*inv(xprimex)*xx'; r‘= rcross=r'./(1-diag(E)')

6 Regress for wrong function
>> [b,bint,r,rint,stats] = regress(yq',xx); b = bint = stats = 1.0e+03 * sighat=sqrt(stats(4))=0.6924

7 Corresponding residuals and cross validation “errors”
r' rcross=r'./(1-diag(E)')

8 Prediction variance (noisy data)
Formula from lecture Check that at data points predvar=sighat*sqrt(diag(E))' yfit =

9 For wrong function predvar=sighat*sqrt(diag(E))' predvar = >> r' >>


Download ppt "Curve fitting with polyfit"

Similar presentations


Ads by Google