问题
I know its a stupid question, but I have no idea how to solve it... Lets say I have something like:
x = fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@mycon)
and later on :
function [c,ceq] = mycon(x)
c = ...
ceq = ...
How to pass additional variables into @mycon
, such as
function [c,ceq] = mycon(x, variable)
if variable == 1
c = ...
ceq = ...
else
c = ...
ceq = ...
end
Thanks :)
回答1:
You pass mycon
as anonymous function:
x = fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@(xx)mycon(xx,variable))
Note that variable
is fixed at the moment the fmincon
line is called.
来源:https://stackoverflow.com/questions/13641590/matlab-fmincon-pass-variables-into-nonlcon