matlab: fmincon, pass variables into nonlcon

拈花ヽ惹草 提交于 2019-12-22 17:45:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!