1% B = SimilarityMatrix(A1, A2)
3% Returns the matrix that transforms A1 to A2.
7% A1 : matrix, shape (N,N)
9% A2 : matrix, shape (M,M)
10% The larger matrix (M>=N)
14% B : matrix, shape (N,M)
15% The matrix satisfying `A_1\,B = B\,A_2`
19% For the existence of a (unique) solution the larger
20% matrix has to inherit the eigenvalues of the smaller one.
22function B = SimilarityMatrix (A1, A2)
24 if size(A1,1)~=size(A1,2) || size(A2,1)~=size(A2,2)
25 error('SimilarityMatrix: The input matrices must be square!');
32 error('SimilarityMatrix: The first input matrix must be smaller than the second one!');
35 [Q1,R1]=schur(A1,'complex');
36 [Q2,R2]=schur(A2,'complex');
47 m = -R1(k,k+1:end)*X(k+1:end,:);
49 X(k,:) = linsolve([M,c1]',[m,c2(k)]')';