
getf("kronecker.sci");

// Tests:
A = [
    0, 1, 0;
    0, 0, 1
    ];

B = [1,0,0;
     0,1,0
     ];

// Tests:
A = [1,0,0,0,0,0,0,0; // finite eigenvalue
     0,2,0,0,0,0,0,0; // finite eigenvalue
     0,0,0,1,0,0,0,0; // row Kronecker index 2
     0,0,0,0,1,0,0,0; // row Kronecker index 2
     0,0,0,0,0,0,0,0; // column Kronecker index 1
     0,0,0,0,0,1,0,0; // column Kronecker index 1
     0,0,0,0,0,0,3,0; // infinite eigenvalue
     0,0,0,0,0,0,0,3 // infinite eigenvalue
    ];

B = [
    1,0,0,0,0,0,0,0;
    0,1,0,0,0,0,0,0;
    0,0,1,0,0,0,0,0;
    0,0,0,1,0,0,0,0;
    0,0,0,0,0,1,0,0;
    0,0,0,0,0,0,0,0;
    0,0,0,0,0,0,0,1; // infinite eigenvalue
    0,0,0,0,0,0,0,0 // infinite eigenvalue
    ];

N = 10;
M = 10;

[m,n] = size(A);

A = [A,zeros(m,N);
     zeros(M,n),rand(M,N)];

B = [B,zeros(m,N);
     zeros(M,n),rand(M,N)];
     

[U,S,V] = svd(rand(A));

A = U*A*V;
B = U*B*V;


[An, Bn, U, V, l, m, n, r, s] = pencil_colstruct( A, B );
[An, Bn, U, V, l, m, n, r, s] = pencil_rowstruct( A, B );
[An, Bn, U, V, m, n, nf, ni] = pencil_struct( A, B );

//////////////////////////////////////////////////////////////////////
// Controllability
// Simple example:
A = diag(1:5);
E = eye(A);
B = [zeros(4,1);1];

[U,S,V] = svd(rand(A));

A = U*A*U';
B = U*B;


E = diag([1:5,zeros(1,5)]);
A = diag([zeros(1,5),6:10]);
B = [zeros(4,1);1;1;zeros(4,1)];


[U,S,V] = svd(rand(E));

// A regular pencil:
E = U*E*V;
A = U*A*V;

B = U*B;


[ U, V, En, An, Bn, c ] = pencil_contr( A, B, E )
