MATLAB: Second order polynomial coefficients with one equation

coefficientsleast squarespolynomialsolve

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!

Best Answer

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.
Related Question