フィルターのクリア

Higher order polynomial regression

3 ビュー (過去 30 日間)
Marina
Marina 2014 年 5 月 18 日
コメント済み: Image Analyst 2014 年 5 月 19 日
I have to run a regression of order 5. My X matrix is
102.1750
108.0515
102.1785
100.9413
102.6634
My Y matrix is
0
5.4810
7.6267
24.7082
7.7284
Both X and Y are approxiately 20x1, I just wanted to give an idea how they look like.
I have tried the following:
1. Beta=pinv(X'*X)*(X'*Y);
2. Beta=(X'*X)\(X'*Y);
3. Beta=(X*Y);
4. Beta=polyfit(X,Y,5);
Expected=polyval(Beta,X);
The results are very different. Additionally polyfit/polyval shows the following warning:"Warning: Polynomial is not unique; degree >= number of data points"
Any ideas or suggestions of what am I doing wrong or how or what else can I try? What is the correct way to do it?

採用された回答

Star Strider
Star Strider 2014 年 5 月 18 日
Give polyfit your entire (20x1) X and Y arrays, not simply the first five values.
Do that, then only use these lines to do your regression:
Beta=polyfit(X,Y,5);
Expected=polyval(Beta,X);
That should work.
  2 件のコメント
Marina
Marina 2014 年 5 月 19 日
I still get this warning "Polynomial is not unique; degree >= number of data points. " Is there any other way?
Image Analyst
Image Analyst 2014 年 5 月 19 日
You're not passing in all 20 points. You're just passing in 5 of them!!! Prove it by doing this
whos X
whos Y

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 5 月 18 日
coefficients = polyfit(x, y, 5);
% Put training points back in
yFitted = polyfit(coefficients, x);
plot(x,y, 'bs');
hold on
plot(x, yfitted, 'rd-', 'LineWidth', 3);
grid on;

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by