fminsearch + objective function with variable input arguments
显示 更早的评论
Hello,
I am relatively new to MATLAB and this is actually my first question, so I thank everyone in advance who takes the time to answer.
I am developing an optimization algorithm which can solve a specific problem using a variable amount of optimization parameters. The idea is to run an objective function multiple times with an increasing number of parameters so that in the end I can evaluate the optimization results vs the complexity (number of parameters).
I would like to know if is there a way of generating a handle to the objective function with a variable amount of parameters. Right now I am using a very inelegant approach like:
switch numberParameters
case 1
hObjectiveFunction = @(paramOpt) objectiveFunction(paramOpt(1));
case 2
hObjectiveFunction = @(paramOpt) objectiveFunction(paramOpt(1),...
paramOpt(2));
case i
hObjectiveFunction = @(paramOpt) objectiveFunction(paramOpt(1),...
paramOpt(2),...
...
paramOpt(i));
end
fminsearchbnd(hObjectiveFunction, x0)
As you can see this is very bothersome as I would need to explicitly write the number of optimization parameters that I would like to have.
Does anyone have any idea how to do it in a more elegant way, without having to code all the options?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!