minf(x)\\
s.t.\begin{cases}
Ax \leq B\\
Aeq \cdot x=Beq\\
C(x)\leq 0\\
Ceq(x) = 0
\end{cases}
[x,fval]=fmincon(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON)
minf(x)=x_1^2+x_2^2+8\\
s,t.\begin{cases}
x_1^2-x_2 \geq 0\\
-x_1-x_2^2+2=0\\
x_1,x_2\geq 0
\end{cases}
//fun1.m
function f = fun1(x)
f = x(1)^2 + x(2)^2 + 8;
end
//fun2.m
function [c,ceq] = fun2(x)
c = -x(1)^2+x(2);
ceq = -x(1)-x(2)^2+2;
end
//main.m
[x,fval] = fmincon(@fun1,rand(2,1),[],[],[],[],zeros(2,1),[],@fun2);
disp(x);
disp(fval);
本文章使用limfx的vscode插件快速发布