필터 지우기
필터 지우기

Second order polynomial coefficients with one equation

조회 수: 12 (최근 30일)
Andreas Volden
Andreas Volden 2014년 11월 30일
댓글: Image Analyst 2017년 11월 19일
Hi! I have the following equation: y=c*u+d*u^2
Known variables are y and u for a given timeseries. c and d are unknown constants. Observe that it don't exist a constant term in the equation.
I'm sure that one solution lies within least squares, but I've sort of given up without assistance. Is there another, less complex way to solve this pherhaps?
Anyone who could help progress with this problem?
Thanks!
  댓글 수: 3
Andreas Volden
Andreas Volden 2014년 11월 30일
OK. Thank you!
Star Strider
Star Strider 2014년 11월 30일
My pleasure!

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

채택된 답변

Image Analyst
Image Analyst 2014년 12월 1일
I don't see Azzi's solution here any longer so I'll just give the standard least squares solution here:
This is your model:
y = alpha1 * u + alpha2 * u^2
I don't think you can use polyfit() because there's no constant term, but you can use the standard least squares formula
alpha = inv(x' * x) * x' * y; % Get estimate of the alphas.
Where x = an N rows by 2 columns matrix.
u(1), u(1)^2
u(2), u(2)^2
u(3), u(3)^2
u(4), u(4)^2
...
u(N), u(N)^2
Now of course alpha(1) is what you called c and alpha(2) is what you called d. This is pretty much just straight out of the least squares derivation in a textbook of mine.

추가 답변 (1개)

MariapL
MariapL 2017년 11월 19일
hi , I am new here, looking for a solution for the same problem. I am trying to use what you said in matlab, but its not working. Could you please take a look ? Maybe you will know what I am doing wrong. So I have the same equation: y=aN^2+bN , with coefficient c already set as 0. I am typing in matlab ( my date is a time series)
x=[0 1 2 3 4 5]
y=[100 250 680 150 200 221]
y = alpha1 * x + alpha2 * x^2
alpha = inv(x' * x) * x' * y
But I will need alpha1 and alpha2 to be known in matlab in order for this to work. I dont get what should I do here to get this two coefficient.
  댓글 수: 4
Star Strider
Star Strider 2017년 11월 19일
As always, my pleasure!
Image Analyst
Image Analyst 2017년 11월 19일
No, you don't put X into the alpha equation, you put the matrix built from X, like this:
x=[0 1 2 3 4 5]
y=[100 250 680 150 200 221]
plot(x, y, 'b*');
A = [x', x'.^2]
alpha = inv(A' * A) * A' * y'
% yFit = alpha1 * x + alpha2 * x^2
yFit = alpha(1) * x + alpha(2) * x.^2
hold on;
plot(x, yFit, 'rd-');
grid on;
legend('Training data', 'Fitted Data');

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by