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 :)
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.