MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

How can I create a best fit polynomial for my data?

Syed Ali Zaryab さんによって質問されました 2018 年 9 月 4 日
最新アクティビティ Titus Edelhofer
さんによって コメントされました 2018 年 9 月 9 日
I have a set of data points that I received from a supplier which gives relative efficiency based on values of x and y. I want to create a polynomial similar to the one given below using the data provided Efficiency = a * (x)^2 + b * (x*y) + c * (y)^2 + d * (x)+ e * (y) + f
So basically what I want is a function which optimizes the value of a,b,c,d,e and f for me and gives me results that are almost similar to the one in the data table.
Attached herewith is the picture of the graph that the supplier provided along with the data points. Can you please tell me what functions can I use in Matlab to help me achieve this task.

  0 件のコメント

サインイン to comment.

1 件の回答

回答者: Titus Edelhofer
2018 年 9 月 4 日

Hi Syed,
if I assume you have three (column) vectors x, y and Efficiency, then it's simply a linear regression problem:
A = [x.^2 x.*y y.^2 x y ones(size(x))];
sol = A \ Efficiency;
Then sol contains the (best approximation) values a,...,f.
Titus

  3 件のコメント

Dear Titus,
I tried to implement your suggestion and wrote the following bit of code
x = [0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1;
0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1;
0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1;
0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1];
eff = [.9 .9 .9 .9 .9 .9 .9 .9 .9 .9 .9 .9 .9;
.95 .95 .95 .95 .95 .95 .95 .95 .95 .95 .95 .95 .95;
.9667 .9667 .9667 .9667 .9667 .9667 .9667 .9667 .9667 .9667 .9667 .9667 .9667;
.9833 .9833 .9833 .9833 .9833 .9833 .9833 .9833 .9833 .9833 .9833 .9833 .9833];
y= [0.93 0.91 0.89 0.87 0.85 0.84 0.835 0.83 0.83 0.835 0.84 0.85 0.86;
0 0 0 1.27 1.1 1.04 1 0.99 0.98 0.975 0.97 0.98 0.99 ;
0 0 0 0 0 0 0 0 1.07 1.03 1.025 1.025 1.03;
0 0 0 0 0 0 0 0 0 0 0 1.1 1.07 ];
A = [x.^2 x.*y y.^2 x y ones(size(x))];
sol = A \ eff;
sol;
but over here I am getting sol as a matrix. I believe I am making a mistake somewhere.
Also I would like to see the scatter plot as well as the best fit plot. But I dont know how to see them.
Thanks for the help.
Ali
Torsten
2018 年 9 月 7 日
Use "reshape" to change x, eff and y from (4x13) matrices to (52x1) vectors.
Titus Edelhofer
2018 年 9 月 9 日
Or use (:), i.e.,
x = x(:);
y = y(:);
eff = eff(:);
Titus

サインイン to comment.



Translated by