www.gusucode.com > mpc 案例源码 matlab代码程序 > mpc/SolveGeneralQuadraticProgrammingProblemExample.m
%% Solve Quadratic Programming Problem % Find the values of _x_ that minimize %% % % $$f\left( x \right) = 0.5x_1^2 + x_2^2 - {x_1}{x_2} - 2{x_1} - 6{x_2},$$ % %% % subject to the constraints %% % % $$\begin{array}{l} % {x_1} \ge 0\\ % {x_2} \ge 0\\ % {x_1} + {x_2} \le 2\\ % - {x_1} + 2{x_2} \le 2\\ % 2{x_1} + {x_2} \le 3. % \end{array}$$ % %% % Specify the Hessian and linear multiplier vector for the objective % function. % Copyright 2015 The MathWorks, Inc. H = [1 -1; -1 2]; f = [-2; -6]; %% % Specify the ineqaulity constraint parameters. A = [1 0; 0 1; -1 -1; 1 -2; -2 -1]; b = [0; 0; -2; -2; -3]; %% % 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); %% % It is good practice to 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] = mpcqpsolver(Linv,f,A,b,Aeq,beq,iA0,opt); %% % Examine the solution, |x|. x