How to fit multivariable equation?

2 ビュー (過去 30 日間)
Caglar
Caglar 2019 年 7 月 15 日
コメント済み: Torsten 2019 年 7 月 15 日
I have n x 3 input data (n amount of examples for three properties) and n x 1 output data from real world observations. n is the number of examples I have.
In other words,
Inputs:
inputs=[1 2 3;
4 5 7;
2 4 6;
2 1 1;
....];
Outputs:
outputs=[15; 26; 29; 8...];
From my experience on the subject, I expect there is a relationship similar to:
output=input(1)*coef1+input(2)*coef2+input(3)*coef3+coef4;
How can I use matlab to find coef1, coef2, coef3 and coef4? I checked curve fiting and optimization help pages but I could not be sure about the best way.
(I guess I can drop the term coef4 if it makes things much harder to code beacuse I expect coef4 to be small.)
For example, for the numbers I wrote above (inputs and outputs), relationship is;
input(1)+2*input(2)+3*input(3)+1
so coef1 is 1, coef2 is 2, coef3 is 3 and coef4 is 1.
In real life values, equation will not fit exactly like this due to noise of the data.
Thank you,

回答 (1 件)

Torsten
Torsten 2019 年 7 月 15 日
編集済み: Torsten 2019 年 7 月 15 日
coeffs = [inputs, ones(size(inputs,1),1)] \ outputs
  2 件のコメント
Caglar
Caglar 2019 年 7 月 15 日
Hi, thank you for your answer. I am aware this particular case can be solved by linear algebra but I was wondering for more general solutions incase my expected equaion is not correct. Could you also help with that?
Torsten
Torsten 2019 年 7 月 15 日
It is the general solution to minimize ||[inputs,1]*coeffs - outputs|| in the least squares sense.

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

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by