www.gusucode.com > mpc 案例源码 matlab代码程序 > mpc/CheckActiveInequalityConstraintsForQPSolutionExample.m
%% Check Active Inequality Constraints for QP Solution % Find the values of _x_ that minimize %% % % $$f\left( x \right) = 3x_1^2 + 0.5x_2^2 - 2{x_1}{x_2} - 3{x_1} + 4{x_2},$$ % %% % subject to the constraints %% % % $$\begin{array}{l} % {x_1} \ge 0\\ % {x_1} + {x_2} \le 5\\ % {x_1} + 2{x_2} \le 7. % \end{array}$$ % %% % Specify the Hessian and linear multiplier vector for the objective % function. % Copyright 2015 The MathWorks, Inc. H = [6 -2; -2 1]; f = [-3; 4]; %% % Specify the ineqaulity constraint parameters. A = [1 0; -1 -1; -1 -2]; b = [0; -5; -7]; %% % Define Aeq and beq to indicate that there are no equality constraints. Aeq = []; beq = zeros(0,1); %% % Find the lower-triangular Cholesky decomposition of |H|. [L,p] = chol(H,'lower'); Linv = inv(L); %% % Verify that |H| is positive definite by checking if |p = 0|. p %% % Create a default option set for |mpcqpsolver|. opt = mpcqpsolverOptions; %% % To cold start the solver, define all inequality constraints as inactive. iA0 = false(size(b)); %% % Solve the QP problem. [x,status,iA,lambda] = mpcqpsolver(Linv,f,A,b,Aeq,beq,iA0,opt); %% % Check the active inequality constraints. An active inequality constraint % is at equality for the optimal solution. iA %% % There is a single active inequality constraint. %% % View the Lagrange multiplier for this constraint. lambda.ineqlin(1)