I\'m having trouble understanding and applying the use of nlinfit
function in Matlab. So, let\'s say I\'m given vectors
x = [1, 2, 3, 4, 5]
y
Check out the second example in the docs: http://www.mathworks.com/help/stats/nlinfit.html
Basically you pass a function handle as your modelfunction
parameter. Either make a function in a file and then just pass it the function name with an @
in front or else make an anonymous function like this:
nlinfit(x, y, @(b,x)(b(1).*exp(b(2).*x) + b(3)), beta0)
You'll notice that in the above I have stuck all your parameters into a single vector. The first parameter of your function must be a vector of all the points you are trying to solve for (i.e. A
, B
and C
in your case) and the second must be x
.
As woodchips has said beta0
is your starting point so your best guess (doesn't have to be great) of your A
, B
and C
parameters. so something like [1 1 1]
or rand(3,1)
, it is very problem specific though. You should play around with a few. Just remember that this is a local search function and thus can get stuck on local optima so your starting points can actually be quite important.
beta0 is your initial guess at the parameters. The better your guess, the more likely you will see convergence to a viable solution. nlinfit is no more than an optimization. It has to start somewhere.