Hello I wanted to write code in matlab "without using any toolbox" to do the following things, can we do like this?

1 view (last 30 days)
This is the equation calc_value = C0+C1*N+C2*N^2+C3*P1+C4*P2
where C0-C4 = coefficients N, P1, P2 = input values Now suppose the actual value = x
So, error = calc_value - actual value(x)
I squared the error = error^2
Now I want to minimize the sum of error^2 by adjusting the coefficients C0-C4 in the above equations (like we use solver in excel)
Note: Here the actual values and the inputs are available, I don't want to use any toolboxes
this is my table
N N^2 P1 P2 calc actual error error^2
please help if anyone has the idea...
Thanks Vishal
  3 Comments
Vishal Halale
Vishal Halale on 5 Dec 2013
At start I am assuming the coefficients c0-c4 = 1 then with the help of that I am calculating the value and with using those values finding the error. Then again minimizing the error by adjusting the assumed coefficients. Did you get it?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 4 Dec 2013
Can't you just use least squares, like
coefficients = calc_value / yourTable;
or something like that? Of course the table would not include calc, actual, error, and must have a column of 1's to start
1, N1, N1^2, P11, P21;
1, N2, N2^2, P12, P22;
1, N3, N3^2, P13, P23;
etc.
Or use the standard least squares solution
Where X is the table I gave above, and y is your calc_values, and beta is your Cn coefficients.
  1 Comment
Vishal Halale
Vishal Halale on 5 Dec 2013
Hey Thanks for the reply. Here See this Image It will give you the clear idea what I wanted. Please write some code also if you know, coz I am new to matlab. All I wanted out of this table is the correct/matlab calculated values of c0-c4 which will minimize the error^2.
Thanks.

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!