Computing the parameters of a model

조회 수: 2 (최근 30일)
Joe
Joe 2013년 4월 7일
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?

채택된 답변

Image Analyst
Image Analyst 2013년 4월 7일
편집: Image Analyst 2013년 4월 7일
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
Joe
Joe 2013년 4월 7일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by