转自百度知道,
https://zhidao.baidu.com/question/343529503.html
help fmincon最下面有这个例子
function f = myfun(x,a1)
f = x(1)^2 + a1*x(2)^2;
function [c,ceq] = mycon(x, a2 )
c = a2 /x(1) - x(2);
ceq = [];
a1 = 2; a2 = 1.5 ; % define parameters first
options = optimset('Algorithm','interior-point'); % run interior-point algorithm
x = fmincon(@(x) myfun(x,a1),[1;2],[],[],[],[],[],[],@(x) mycon(x,a2),options)
c为非线性不等式约束。ceq为非线性等式约束。因为c = a2/x(1) - x(2);
所以你的ceq可以参考这样写。比如ceq=a2*x(1)^2-x(1)*x(2)。
function f = myfun(x,a1)
f = x(1)^2 + a1*x(2)^2;
function [c,ceq] = mycon(x, a2 )
c = a2 /x(1) - x(2);
ceq = [];
a1 = 2; a2 = 1.5 ; % define parameters first
options = optimset('Algorithm','interior-point'); % run interior-point algorithm
x = fmincon(@(x) myfun(x,a1),[1;2],[],[],[],[],[],[],@(x) mycon(x,a2),options)
c为非线性不等式约束。ceq为非线性等式约束。因为c = a2/x(1) - x(2);
所以你的ceq可以参考这样写。比如ceq=a2*x(1)^2-x(1)*x(2)。