更新时间:2023-02-27 10:31:58
查看文档中的第二个示例: http://www.mathworks.com/help/stats/nlinfit.html
Check out the second example in the docs: http://www.mathworks.com/help/stats/nlinfit.html
基本上,您将函数句柄作为您的modelfunction
参数传递.要么在文件中创建一个函数,然后在函数名称前传递一个@
,要么创建一个匿名函数,如下所示:
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)
您会注意到,在上文中,我将所有参数都固定在一个向量中.函数的第一个参数必须是要尝试求解的所有点的矢量(例如,在您的情况下为A
,B
和C
),第二个必须为x
.
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
.
就像木片所说的那样,beta0
是您的起点,因此,您对A
,B
和C
参数的***猜测(不一定是很大的).所以类似[1 1 1]
或rand(3,1)
的东西,这是非常特定于问题的.您应该玩一些.请记住,这是一个本地搜索功能,因此可能会卡在本地最优值上,因此您的出发点实际上可能非常重要.
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.