Why do the fitting coefficients for polyfit change depending on the number of outputs?

8 vues (au cours des 30 derniers jours)
Curious to why the fitting coefficients produced by polyfit() change depending on the number of outputs requested. For example,
This produces,
x = 1:100;
y = -0.3*x + 2*randn(1,100);
[p,S] = polyfit(x,y,1);
p =
-0.3050 0.0635
While this produces,
[p,S,mu] = polyfit(x,y,1);
p =
-8.8479 -15.3380
Thanks for the feedback

Réponse acceptée

Steven Lord
Steven Lord le 17 Juil 2019
Modifié(e) : Steven Lord le 17 Juil 2019
See the third item in the Description section of the polyfit documentation page. That third output tells MATLAB to center and scale your data. That centered and scaled data is used in place of the "raw" x data to create the polynomial fit.
As stated in the description of the mu output argument on that documentation page, if you ask for the third output from polyfit you'll need to specify that output as an input when or if you call polyval. This will tell polyval how to transform your data before evaluating the fit.
Looking at the data from the "Use Centering and Scaling to Improve Numerical Properties" on that documentation page, would you rather work with data on the order of 3.2e16 to fit a fifth degree polynomial or data on the order of 8?
>> x = 1750:25:2000;
>> max(x.^5)
ans =
3.2000e+16
>> xnorm = normalize(x, 'zscore');
>> max(xnorm.^5)
ans =
7.7870

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by