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

8 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Steven Lord
Steven Lord el 17 de Jul. de 2019
Editada: Steven Lord el 17 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by