# Section 6.1.2: Residual minimization with deadzone penalty

Jump to: Source code Text output Plots Library index

    % Boyd & Vandenberghe "Convex Optimization"
    % Joelle Skaf - 08/17/05
    %
    % The penalty function approximation problem has the form:
    %               minimize    sum(deadzone(Ax - b))
    % where 'deadzone' is the deadzone penalty function
    %               deadzone(y) = max(abs(y)-1,0)

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

    % deadzone penalty
    % 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 sedumi: 72 variables, 32 equality constraints
    ------------------------------------------------------------
    SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
    Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
    Split 8 free variables
    eqs m = 32, order n = 81, dim = 81, blocks = 1
    nnz(A) = 352 + 0, nnz(ADA) = 304, nnz(L) = 168
     it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
      0 :            6.20E+00 0.000
      1 :  -1.42E+00 2.69E+00 0.000 0.4337 0.9000 0.9000   5.36  1  1  1.5E+00
      2 :  -4.54E-01 6.48E-01 0.000 0.2410 0.9000 0.9000   1.62  1  1  5.4E-01
      3 :  -2.62E-02 2.88E-02 0.000 0.0445 0.9900 0.9900   1.24  1  1  3.9E-01
      4 :  -7.82E-07 2.34E-06 0.000 0.0001 1.0000 1.0000   1.02  1  1
    iter seconds digits       c*x               b*y
      4      0.0   Inf  0.0000000000e+00  3.3683775920e-21
    |Ax-b| =   1.3e-15, [Ay-c]_+ =   1.7E-20, |x|=  4.0e+00, |y|=  2.5e-20

    Detailed timing (sec)
       Pre          IPM          Post
    1.000E-02    2.000E-02    0.000E+00
    Max-norms: ||b||=1.488490e+00, ||c|| = 1,
    Cholesky |add|=0, |skip| = 0, ||L.L|| = 1.2986.
    ------------------------------------------------------------
    Status: Solved
    Optimal value (cvx_optval): +0
    Done!

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

    Optimal vector:
       x     = [  0.3009  0.1246 -0.3517  0.0609  0.6159  0.3661 -0.6500  0.7015 ]
    Residual vector:
       A*x-b = [  0.5895  0.4108 -0.8204 -0.3101  0.3765  0.3674 -0.6425 -0.6953 -0.4972  0.7696  0.1634 -0.1903  0.5290  0.7479  0.2976 -0.3825 ]