polyfit with multiple dependent variables

121 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2020 年 12 月 17 日
コメント済み: alpedhuez 2020 年 12 月 17 日
I think
can handle multiple dependent variables. But when I tried
Fit = polyfit([x1 x2], x3, 1);
I got an error message
Error using polyfit (line 44)
The first two inputs must have the same number of elements.
Although I checked x1, x2, x3 has the same length. What can one do?

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 12 月 17 日
The polyfit function only works for 1-D polynomials, as far as I understand things. However there is an n-dimensional polynomial-fitting function package on the file exchange: polyfitn. That should give you the tools necessary to solve this problem. I've used it without much problems and to sensible success.
HTH
  1 件のコメント
alpedhuez
alpedhuez 2020 年 12 月 17 日
Thank you.

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

その他の回答 (1 件)

Remy Lassalle-Balier
Remy Lassalle-Balier 2020 年 12 月 17 日
I think polyfit does not suport multiple dependent variables. The documentation is quite clear about the fact the first parameter should be a vector and not a matrix.
You can still run your fit manually:
X = [ ones( numel( x1 ) , 1 ) , x1(:) , x2(:) ];
fitParam = X\x3(:);
Fittedx3 = X * fitParam;
This is better explained here.
  1 件のコメント
alpedhuez
alpedhuez 2020 年 12 月 17 日
True.

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by