Computing the parameters of a model

2 views (last 30 days)
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?

Accepted Answer

Image Analyst
Image Analyst on 7 Apr 2013
Edited: Image Analyst on 7 Apr 2013
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);
  1 Comment
Joe
Joe on 7 Apr 2013
Well when I said y is not given, I meant that the specific values of y are not given. However, now that I think about it the given function computes y for whatever x I put in, so in this case I would know the values of y....oh I guess I was over-thinking this. Thank you very much though for making me realize my mistake.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics 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!