Using fminunc to find coefficients

I have a data table:
x: 0 1 2 3 4 5 6 7 8 9
y: -1 6 13 20 21 19 15 8 -2 -3
I have the functional form of the data to be : y = ax^2 + bx + c
My professor told us that we can use the matlab function fminunc to find the coefficients a, b and c but I can't seem to find any information on how to do this.
I know I can use the fittype and fit commands to do this, but I would like to know if it is possible to use fminunc, and if it is how would I go about it.

 Accepted Answer

Let f(x, a, b, c) be a function that takes x locations and model parameters a, b, c, and projects a y. Then
residue = sum((y - f(x, a, b, c)).^2)
would be minimized when trial values a, b, c are the best approximations to the theoretical a, b, c (approximations because there might be noise in the readings.)
Now fminunc expects a function handle with only one parameter, which is a vector of trial values, rather than expecting a function handle that takes four inputs. The way to handle that is to "parameterize" http://www.mathworks.com/help/matlab/math/parameterizing-functions.html
fmincon( @(abc) sum((y-f(x, abc(1), abc(2), abc(3)).^2), ........)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!