```% Boyd & Vandenberghe "Convex Optimization"
% Joelle Skaf - 08/17/05
%
% The penalty function approximation problem has the form:

% Input data
randn('state',0);
m = 16; n = 8;
A = randn(m,n);
b = randn(m,1);

% original formulation
fprintf(1,'Computing the optimal solution of the deadzone approximation problem: \n');

cvx_begin
variable x(n)
minimize( sum(max(abs(A*x-b)-1,0)) )
cvx_end

fprintf(1,'Done! \n');

% Compare
disp( sprintf( '\nResults:\n--------\nsum(max(abs(A*x-b)-1,0)): %6.4f\ncvx_optval: %6.4f\ncvx_status: %s\n', sum(max(abs(A*x-b)-1,0)), cvx_optval, cvx_status ) );
disp( 'Optimal vector:' );
disp( [ '   x     = [ ', sprintf( '%7.4f ', x ), ']' ] );
disp( 'Residual vector:' );
disp( [ '   A*x-b = [ ', sprintf( '%7.4f ', A*x-b ), ']' ] );
disp( ' ' );
```
```Computing the optimal solution of the deadzone approximation problem:

Calling SDPT3 4.0: 72 variables, 32 equality constraints
------------------------------------------------------------

num. of constraints = 32
dim. of socp   var  = 32,   num. of socp blk  = 16
dim. of linear var  = 32
dim. of free   var  =  8 *** convert ublk to lblk
*******************************************************************
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|7.4e-01|2.3e+01|1.8e+04| 2.252324e+02  0.000000e+00| 0:0:00| chol  1  1
1|1.000|0.835|2.4e-06|3.9e+00|1.5e+03| 2.732368e+02 -3.160464e+01| 0:0:00| chol  1  1
2|1.000|0.988|4.3e-06|5.6e-02|1.6e+02| 1.373391e+02 -1.280265e+01| 0:0:00| chol  1  1
3|0.896|0.969|1.6e-06|2.6e-03|1.7e+01| 6.468687e+00 -1.056104e+01| 0:0:00| chol  1  1
4|1.000|0.029|3.5e-06|3.2e-03|1.7e+01| 5.676729e+00 -1.024814e+01| 0:0:00| chol  1  1
5|0.649|0.474|2.0e-06|1.7e-03|1.1e+01| 4.684397e+00 -5.922458e+00| 0:0:00| chol  1  1
6|0.929|0.307|5.9e-07|1.2e-03|6.5e+00| 1.975882e+00 -4.346206e+00| 0:0:00| chol  1  1
7|1.000|0.416|3.9e-07|6.9e-04|3.5e+00| 7.427569e-01 -2.708758e+00| 0:0:00| chol  1  1
8|1.000|0.554|1.0e-07|3.1e-04|1.5e+00| 1.716839e-01 -1.269672e+00| 0:0:00| chol  1  1
9|0.999|0.891|1.8e-08|3.4e-05|1.5e-01| 5.764868e-03 -1.408961e-01| 0:0:00| chol  1  1
10|0.987|0.986|1.3e-09|4.8e-07|2.1e-03| 7.881245e-05 -2.003151e-03| 0:0:00| chol  1  1
11|0.989|0.989|6.3e-11|1.0e-05|7.1e-05| 8.706354e-07 -2.251729e-05| 0:0:00| chol  1  1
12|1.000|0.988|8.2e-14|3.5e-07|2.2e-06| 1.560505e-07 -5.703412e-07| 0:0:00| chol  1  1
13|1.000|0.988|4.4e-15|1.1e-08|6.6e-08| 4.842104e-09 -1.628348e-08| 0:0:00| chol  1  1
14|1.000|0.912|1.7e-16|4.0e-10|2.0e-08| 6.148509e-09 -1.262963e-08| 0:0:00| chol  1  1
15|1.000|0.607|1.5e-15|1.4e-10|8.7e-09| 1.449139e-09 -6.710838e-09| 0:0:00|
stop: max(relative gap, infeasibilities) < 1.49e-08
-------------------------------------------------------------------
number of iterations   = 15
primal objective value =  1.44913896e-09
dual   objective value = -6.71083785e-09
gap := trace(XZ)       = 8.69e-09
relative gap           = 8.69e-09
actual relative gap    = 8.16e-09
rel. primal infeas (scaled problem)   = 1.48e-15
rel. dual     "        "       "      = 1.38e-10
rel. primal infeas (unscaled problem) = 0.00e+00
rel. dual     "        "       "      = 0.00e+00
norm(X), norm(y), norm(Z) = 4.0e+00, 4.6e-09, 4.0e+00
norm(A), norm(b), norm(C) = 1.7e+01, 6.4e+00, 5.0e+00
Total CPU time (secs)  = 0.22
CPU time per iteration = 0.01
termination code       =  0
DIMACS: 3.8e-15  0.0e+00  3.4e-10  0.0e+00  8.2e-09  8.7e-09
-------------------------------------------------------------------

------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +1.44914e-09

Done!

Results:
--------
sum(max(abs(A*x-b)-1,0)): 0.0000
cvx_optval: 0.0000
cvx_status: Solved

Optimal vector:
x     = [  0.3334  0.0993 -0.3344  0.0608  0.6061  0.3877 -0.6685  0.7438 ]
Residual vector:
A*x-b = [  0.6199  0.3678 -0.8146 -0.2921  0.3308  0.4011 -0.6790 -0.7038 -0.4704  0.7816  0.0804 -0.0987  0.5240  0.7539  0.2686 -0.3702 ]

```