Hello,
I have to send some additional arguments to my objective function fun.
If I do this, I get an error saying that I have too many input arguments.
[xn3,fvaln3,exitflagn3,outputn3] = particleswarm(@fun,nvars,lb,ub,options, additionalArguments);
Then I tried the following thing but I got an error saying I can't have a structure as an input argument.
[xn3,fvaln3,exitflagn3,outputn3] = particleswarm({@fun,additionalArguments},nvars,lb,ub,options);
Thanks in advance!

 채택된 답변

Alan Weiss
Alan Weiss 2016년 5월 12일

1 개 추천

That older way of passing additional arguments is supported but not documented for older functions. Newer functions do not support it at all.
For supported, documented ways of passing extra parameters, see the documentation.
Alan Weiss
MATLAB mathematical toolbox documentation

댓글 수: 3

I am a bit confused - does it mean that newer functions don't support passing extra parameters at all? Or it means I can pass the parameters only like it is described in the documentation?
In my case, I still have the error of too many input arguments. I tried the anonymous functions approach.
f = @(Param)CostFcn(Param,Fz,SSA,Camber,List,Coeff,Fy);
[Param,fval, exitflag,output] = simulannealbnd(f,...
Param0,...
[],[],[],[],LB,UB,[], options);
and the function is defined as it follows:
function Err = CostFcn(Param,Fz,SSA,Camber,List,Coeff,Yref)
simulannealbnd does not have A, b, Aeq, beq or nonlcon arguments .
[Param,fval, exitflag,output] = simulannealbnd(f, Param0, LB, UB, options);
Luce Ca
Luce Ca 2016년 5월 13일
Sloppy me, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Stalin Samuel
Stalin Samuel 2016년 5월 12일

0 개 추천

You cannot add additional arguments to matlab predefined functions. click hrer for more about particleswarm

댓글 수: 1

Luce Ca
Luce Ca 2016년 5월 12일
편집: Luce Ca 2016년 5월 12일
For other optimisation algorithms and functions I have no problem sending the additional parameters in the two ways I mentioned, i.e. I used the second way in pattern-search.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Optimization Toolbox에 대해 자세히 알아보기

질문:

2016년 5월 12일

댓글:

2016년 5월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by