Computing the parameters of a model

2 Ansichten (letzte 30 Tage)
Joe
Joe am 7 Apr. 2013
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?

Akzeptierte Antwort

Image Analyst
Image Analyst am 7 Apr. 2013
Bearbeitet: Image Analyst am 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 Kommentar
Joe
Joe am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by