Using nlinfit in Matlab?

后端 未结 2 1931
清酒与你
清酒与你 2020-12-19 07:35

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          


        
相关标签:
2条回答
  • 2020-12-19 08:20

    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.

    0 讨论(0)
  • 2020-12-19 08:20

    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.

    0 讨论(0)
提交回复
热议问题