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

9 ビュー (過去 30 日間)
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

採用された回答

Steven Lord
Steven Lord 2019 年 7 月 17 日
編集済み: Steven Lord 2019 年 7 月 17 日
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 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by