Why do the fitting coefficients for polyfit change depending on the number of outputs?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ricardo Rodriguez
il 17 Lug 2019
Modificato: Steven Lord
il 17 Lug 2019
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
0 Commenti
Risposta accettata
Steven Lord
il 17 Lug 2019
Modificato: Steven Lord
il 17 Lug 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
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!