matlab:fmincon,将变量传递给nonlcon [英] matlab: fmincon, pass variables into nonlcon
本文介绍了matlab:fmincon,将变量传递给nonlcon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道它是一个愚蠢的问题,但我不知道如何解决它......让我说我有这样的事情:
x = fmincon(@ myfun,x0,A,b,Aeq,beq,lb,ub,@ mycon)
以及后来的:
函数[c,ceq] = mycon(x)
c = ...
ceq = ...
如何将附加变量传递到 $ mycon
,例如
函数[c,ceq] = mycon(x,变量)
如果变量== 1
c = ...
ceq = ...
else
c = ...
ceq = ...
end
感谢:)
mycon 作为匿名函数传递:
x = fmincon(@ myfun,x0,A,b,Aeq,beq,lb,ub,@(xx)mycon(xx,变量))
请注意,变量
在 fmincon
行被调用。
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.
这篇关于matlab:fmincon,将变量传递给nonlcon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文