MATLAB: Computing the parameters of a model

computelinear equationsparameters

I am having trouble understanding how to code this problem. I have a certain model y(x) = a1 + a2*x + a3*x^2. I need to create a function that computes the parameters a(i) for i = [1 2 3]. I am given the values of x and y is computed in a separate protected function file. However, I don't understand how you compute the parameters if you don't know the specific values of y for specific values of x. I thought maybe you have to call the separate function within the function I am creating, but that's not how it works. If I was given y and x then I could easily compute a(i) because it's just a system of linear equations. So a(i) = x\y but in this case y is not given…so how exactly am I supposed to do this?

Best Answer

There is no way to do it if you don't have y values. Think. How could you possibly figure out the coefficients if all you have is a list of x values. There is absolutely no way.
But you contradict yourself. First you say "y is computed in a separate protected function file" and then you say "y is not given." So do you have y or not? If the answer is no, then there's no way to figure out a(i). Period.
Also be aware that when you use polyfit, the Mathworks reverses the traditional equation like you have (and I use also) so their a(1) is the x^2 coefficient, not the offset
coeffs = polyfit(x, y, 2);
a1 = coeffs(3);
a2 = coeffs(2);
a3 = coeffs(1);