两个例子, 一是用solve函数解带约束条件的方程组, 二是用fmincon函数解带约束条件的最小化问题
一个例子是:
9*x1-3*x2-2*x3-3*x4=0\\ 5*x1-9*x2+2*x3+3*x4=0\\ 2*x1+5*x2-10*x3+3*x4=0\\ 2*x1+x2+6*x3-9*x4=0\\ s.t. \ \ 50<=x_i<=70
接触x_i的值,对应的matlab代码为:
syms x1 x2 x3 x4 [x1,x2,x3,x4,params,conditions] = solve(9*x1-3*x2-2*x3-3*x4==0,9*x2-5*x1-2*x3-3*x4==0,10*x3-2*x1-5*x2-3*x4==0,9*x4-2*x1-x2-6*x3==0,x1>=50,x1<=70,x2>=50,x2<=70,x3>=50,x3<=70,x4>=50,x4<=70,[x1,x2,x3,x4],'ReturnConditions',true) solutions = [x1,x2,x3,x4];
附带上结果: