NCSOStoolsdemo - Nonnegativity on nc ball and nc polydisc and extracting corresponding minimizers

%**************************************************************************

% Nonnegativity on nc ball and nc polydisc and extracting corresponding   *

% minimizers                                                              *

%**************************************************************************

% -------------------------------------------------------------------------

% First we construct some symbolic noncommuting variables and some

% polynomial

% -------------------------------------------------------------------------

>> NCvars x y

>> f = 2 - x^2 + x*y^2*x - y^2;

% -------------------------------------------------------------------------

% We can compute the optimal value on the nc ball

% -------------------------------------------------------------------------

>> NCminBall(f)

***** NCSOStools: module NCminBall started *****

Number of linear constraints: 58.

Starting SDP solver ...

...

Residual norm: 6.3137e-015

 

ans = 1.0000

% -------------------------------------------------------------------------

% Similarly we can compute the optimal value on the nc polydisc

% -------------------------------------------------------------------------

>> NCminCube(f)

***** NCSOStools: module NCminCube started *****

Number of linear constraints: 67.

Starting SDP solver ...

...

Residual norm: 6.4065e-013

ans = 1.0872e-011

% -------------------------------------------------------------------------

% Together with the optimal value opt we can also return a certificate for

% positivity of f-opt for example on nc ball (and similarly on nc

% polydisc), i.e., a sohs decomposition with weights for f-opt.

% -------------------------------------------------------------------------

>> [opt,g,decom_sohs,decom_ball] = NCminBall(f)

***** NCSOStools: module NCminBall started *****

Number of linear constraints: 58.

Starting SDP solver ...

...

Residual norm: 6.3137e-015

opt = 1.0000

g = 1-x^2-y^2

 

decom_sohs =                             0

                                         0

                               -2e-008*x^2

                                 -3e-008*x

                    -5e-008*x*y+1e-008*y^2

             -1e-008+1e-008*x*y+5e-008*y^2

                                       y*x

decom_ball =        1

             2e-008*x

             5e-008*y

 

% -------------------------------------------------------------------------

% NCminBall (and NCminCube) has many optional parameters. For example we

% can set the smallest value that is considered to be nonzero in numerical

% calculations.

% -------------------------------------------------------------------------

>> params.precision=1e-6;

>> [opt,g,decom_sohs,decom_ball] = NCminBall(f,params)

***** NCSOStools: module NCminBall started *****

Number of linear constraints: 58.

Starting SDP solver ...

...

Residual norm: 6.3137e-015

opt = 1.0000

 

g = 1-x^2-y^2

 

decom_sohs =   0

               0

               0

               0

               0

               0

             y*x

 

decom_ball = 1

             0

             0

 

% -------------------------------------------------------------------------

% Let's check the obtained sohs decomposition with weights for f-opt.

% -------------------------------------------------------------------------

>> f-opt

 

ans = 1-x^2+x*y^2*x-y^2

>> decom_sohs'*decom_sohs + decom_ball'*g*decom_ball

 

ans = 1-x^2+x*y^2*x-y^2

 

% -------------------------------------------------------------------------

% We can also compute minimizers to attain optimal value on nc ball.

% -------------------------------------------------------------------------

>> [X,fX,eig_val,eig_vec]=NCoptBall(f)

***** NCSOStools: module NCoptBall started *****

***** NCSOStools: module GNS started *****

found 5 linearly independent vectors ...

using corresponding columns of a matrix ...

using corresponding words in a cell of monomials ...

constructing final matrices ... done.

***** NCSOStools: module GNS completed *****

Evaluating X ..... completed.

*** Minimum eigenvalue for f is 1.000000. ***

WARNING: Optimizers are numerically slightly out of the ball!

Maximal eigenvalue: 1.000000!

***** NCSOStools: module NCoptBall completed with warnings! *****

X = Columns 1 through 8

    -0.0000    0.7107   -0.0000    0.0000    0.0000    0.7107    0.0000   -0.0000

    -0.0000    0.0000    0.7035    0.0000    0.0000    0.0000   -0.0000    0.0000

    Columns 9 through 16

     0.3536   -0.0000   -0.0000   -0.0000   -0.0000    0.0000    0.4946    0.0000

    -0.0000    0.0000    0.7035    0.0000    0.0000   -0.3588    0.0000    0.0000

    Columns 17 through 24

     0.3536    0.0000    0.0000    0.0000    0.0000   -0.0000    0.4946    0.0000

    -0.0000   -0.3588    0.0000   -0.0000    0.0000    0.0000    0.0000   -0.0000

    Column 25

     0.0000

     0.0000

fX = 1.0000   -0.0000   -0.0000    0.0011   -0.0000

    -0.0000    1.5091   -0.0000   -0.0000   -0.0000

    -0.0000   -0.0000    1.1317   -0.0000   -0.0000

     0.0011   -0.0000   -0.0000    1.7462    0.0000

    -0.0000   -0.0000   -0.0000    0.0000    1.9080

eig_val = 1.0000         0         0         0         0

               0    1.1317         0         0         0

               0         0    1.5091         0         0

               0         0         0    1.7462         0

               0         0         0         0    1.9080

eig_vec = -1.0000   -0.0000   -0.0000   -0.0015   -0.0000

          -0.0000    0.0000    1.0000    0.0000   -0.0000

          -0.0000    1.0000   -0.0000    0.0000   -0.0000

           0.0015    0.0000    0.0000   -1.0000    0.0000

          -0.0000    0.0000    0.0000    0.0000    1.0000

% It means that with A=reshape(X(1,:),5,5) and B=reshape(X(2,:),5,5) we get

% f(A,B) as fX with minimal eigenvalue eig_val(1,1) (which is also an

% optimal value on nc ball) and corresponding eigenvector eig_vec(:,1).

% -------------------------------------------------------------------------

% Similarly we can also compute minimizers to attain optimal value on nc

% polydisc).

% -------------------------------------------------------------------------

>> [X,fX,eig_val,eig_vec]=NCoptCube(f)

***** NCSOStools: module NCoptCube started *****

***** NCSOStools: module GNS started *****

found 4 linearly independent vectors ...

using corresponding columns of a matrix ...

using corresponding words in a cell of monomials ...

constructing final matrices ... done.

***** NCSOStools: module GNS completed *****

Evaluating X ..... completed.

*** Minimum eigenvalue for f is 0.000000. ***

***** NCSOStools: module NCoptCube completed *****

X = Columns 1 through 8

    -0.0000    1.0000    0.0000    0.0000    1.0000    0.0000   -0.0000   -0.0000

     0.0000   -0.0000    1.0000    0.0000   -0.0000    0.0000   -0.0000   -0.0000

    Columns 9 through 16

     0.0000   -0.0000   -0.0000    0.7343    0.0000   -0.0000    0.7343    0.0000

     1.0000   -0.0000   -0.0000    0.0000    0.0000   -0.0000    0.0000    0.0000

fX = 0.0000   -0.0000    0.0000   -0.0000

    -0.0000    2.0000    0.0000   -0.0000

     0.0000    0.0000    0.4608   -0.0000

    -0.0000   -0.0000   -0.0000    2.0000

eig_val = 0.0000         0         0         0

               0    0.4608         0         0

               0         0    2.0000         0

               0         0         0    2.0000

eig_vec = 1.0000    0.0000    0.0000    0.0000

          0.0000   -0.0000   -1.0000    0.0000

         -0.0000    1.0000   -0.0000    0.0000

          0.0000    0.0000   -0.0000   -1.0000

% It means that with A=reshape(X(1,:),5,5) and B=reshape(X(2,:),5,5) we get

% f(A,B) as fX with minimal eigenvalue eig_val(1,1) (which is also an

% optimal value on nc polydisc) and corresponding eigenvector eig_vec(:,1).