MATLAB Fundamentals>Common Data Analysis Techniques>Polynomial Fitting>Centering and Scaling
数据导入
This code sets up the activity.
yr = 2000:2007
penguins = [5.49 7.03 7.73 7.70 9.29 9.21 11.89 10.85]
附加练习
How does the model look? Plot the data (penguins
as a function of yr
) as points, then overlay a plot of the model (penguinFit
).
Note that you ignored some inputs and outputs for polyfit
and polyval
. These provide statistical information about the fit, allowing you to do more sophisticated analysis. For example, you can obtain standard error estimates of the predicted fit values.
[c,S,sc] = polyfit(yr,penguins,3)
[penguinFit,serr] = polyval(c,yr,S,sc)
With these, you can calculate a 95% prediction interval.
predInt = penguinFit + 2*[1;-1]*serr
plot(yr,penguins,"o",...yr,penguinFit,yr,predInt,"r--")
结果