[matlab][yalmip]Yalmip安装后测试代码

Yalmip提供了简单的语法,使用户能够轻松地定义凸优化问题。以下是一个示例,用于最小化二次函数:

% Define variables
x = sdpvar(2,1);
% Define objective function
obj = x'*[2 -1;-1 4]*x + [1 2]*x;
% Define constraints
Constraints = [-1 <= x(1) <= 1,0<= x(2) <= 1];
% Define options for the solver
ops = sdpsettings('solver','quadprog');
% Solve the problem
sol = optimize(Constraints,obj,ops);
% Display the solution
disp(value(x))

运行结果:


Minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the default value of the optimality tolerance,
and constraints are satisfied to within the selected value of the constraint tolerance.

<stopping criteria details>

   -0.2500
   -0.0000
 

猜你喜欢

转载自blog.csdn.net/FL1623863129/article/details/131634596