使用优化工具时如何使用输入参数?

时间:2017-02-10 08:59:37

标签: matlab optimization

的main.m

...
param = ...;
x0 = [0,0];
[newX, fval] = fminimax(@myfun, x0)
...

myfun.m

function f = myfun(x)
  f(1)=function of (x, param);
  f(2)=another function of (x, param);
  f(3)=...
  ...
  f(5)=the last function of (x, param);
end

如何将参数'param'传递给myfun文件?

我尝试了以下内容,但发生了错误。

...
param = ...;
x0 = [0,0];
[newX, fval] = fminimax(@myfun, x0, param)
...

function f = myfun(x, param)
  f(1)=function of (x, param);
  f(2)=another function of (x, param);
  f(3)=...
  ...
  f(5)=the last function of (x, param);
end

1 个答案:

答案 0 :(得分:1)

在主要你想要新的功能。像这样:

param = ...;
myfuncinclparam = @(x0)myfun(x0,param)
x0 = [0,0];
[newX, fval] = fminimax(@myfuncinclparam, x0)

进一步参考请检查: https://nl.mathworks.com/help/matlab/ref/fminsearch.html#bvadxhn-9