```% From Boyd & Vandenberghe, "Convex Optimization"
% Joëlle Skaf - 09/26/05
%
% Solves the following QP with inequality constraints:
%           minimize    1/2x'*P*x + q'*x + r
%               s.t.    -1 <= x_i <= 1      for i = 1,2,3
% Also shows that the given x_star is indeed optimal

% Generate data
P = [13 12 -2; 12 17 6; -2 6 12];
q = [-22; -14.5; 13];
r = 1;
n = 3;
x_star = [1;1/2;-1];

% Construct and solve the model
fprintf(1,'Computing the optimal solution ...');
cvx_begin
variable x(n)
minimize ( (1/2)*quad_form(x,P) + q'*x + r)
x >= -1;
x <=  1;
cvx_end
fprintf(1,'Done! \n');

% Display results
disp('------------------------------------------------------------------------');
disp('The computed optimal solution is: ');
disp(x);
disp('The given optimal solution is: ');
disp(x_star);
```
```Computing the optimal solution ...
Calling SDPT3 4.0: 11 variables, 4 equality constraints
For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

num. of constraints =  4
dim. of socp   var  =  5,   num. of socp blk  =  1
dim. of linear var  =  6
*******************************************************************
SDPT3: Infeasible path-following algorithms
*******************************************************************
version  predcorr  gam  expon  scale_data
NT      1      0.000   1        0
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
0|0.000|0.000|9.5e-01|4.3e+00|2.3e+03| 2.204541e+02  0.000000e+00| 0:0:00| chol  1  1
1|1.000|1.000|4.5e-07|5.0e-02|2.0e+02| 2.080252e+02  2.878193e+01| 0:0:00| chol  1  1
2|0.943|0.925|6.8e-08|8.4e-03|1.2e+01| 4.760357e+01  3.641164e+01| 0:0:00| chol  1  1
3|0.791|1.000|4.1e-07|5.0e-04|5.7e+00| 4.293607e+01  3.726829e+01| 0:0:00| chol  1  1
4|1.000|0.888|5.7e-08|1.0e-04|1.4e+00| 4.015948e+01  3.881176e+01| 0:0:00| chol  1  1
5|0.883|1.000|9.4e-09|5.0e-06|3.0e-01| 3.931792e+01  3.901936e+01| 0:0:00| chol  1  1
6|1.000|0.983|2.6e-09|5.8e-07|1.6e-02| 3.913463e+01  3.911827e+01| 0:0:00| chol  1  1
7|0.977|0.972|3.3e-10|6.5e-08|4.2e-04| 3.912522e+01  3.912480e+01| 0:0:00| chol  1  1
8|0.988|0.988|8.6e-12|8.7e-10|5.2e-06| 3.912500e+01  3.912500e+01| 0:0:00| chol  1  1
9|0.996|0.994|6.5e-12|6.9e-12|7.3e-08| 3.912500e+01  3.912500e+01| 0:0:00|
stop: max(relative gap, infeasibilities) < 1.49e-08
-------------------------------------------------------------------
number of iterations   =  9
primal objective value =  3.91250000e+01
dual   objective value =  3.91250000e+01
gap := trace(XZ)       = 7.33e-08
relative gap           = 9.25e-10
actual relative gap    = 9.24e-10
rel. primal infeas (scaled problem)   = 6.53e-12
rel. dual     "        "       "      = 6.87e-12
rel. primal infeas (unscaled problem) = 0.00e+00
rel. dual     "        "       "      = 0.00e+00
norm(X), norm(y), norm(Z) = 3.8e+01, 3.1e+00, 4.2e+00
norm(A), norm(b), norm(C) = 4.3e+00, 3.4e+01, 5.3e+00
Total CPU time (secs)  = 0.12
CPU time per iteration = 0.01
termination code       =  0
DIMACS: 9.5e-12  0.0e+00  1.2e-11  0.0e+00  9.2e-10  9.3e-10
-------------------------------------------------------------------

------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): -21.625

Done!
------------------------------------------------------------------------
The computed optimal solution is:
1.0000
0.5000
-1.0000

The given optimal solution is:
1.0000
0.5000
-1.0000

```