MATLAB fmincon函数调用及函数传参方法
目标函数及约束条件
目标函数
f
(
x
)
=
a
x
1
+
b
f(x) = a{x_1} + b
f(x)=ax1+b
约束条件
{ x 1 − c ≤ 0 x 2 − d ≤ 0 x 2 + x 1 + e = 0 \left\{ \begin{aligned} x _{1}-c&\leq & 0 \\ x _{2}-d&\leq & 0 \\ x _{2}+x _{1} +e &=& 0\\ \end{aligned} \right. ⎩ ⎨ ⎧x1−cx2−dx2+x1+e≤≤=000
fmincon函数matlab 代码
// An highlighted block
options = optimoptions('fmincon','Display','iter','Algorithm','sqp');
[x,fval] = fmincon(@(x)fun1(x,a,b),x0,[],[],[],[],[],[],@(x)fun2(x,c,d,e),options);
function f = fun1(x,a,b)
f = x(1)*a+b;
end
function [c,ceq] = fun2(x,c,d,e)
c = [x(1)-c;x(2)-d];
ceq = x(2)+x(1)+e;
end