1% B = SimilarityMatrixForVectors(vecA, vecB)
3% Returns
the similarity transformation matrix that converts
4% a given
column vector to an other
column vector. It works
5% even with zero entries.
9% vecA :
column vector, shape(M,1)
10% The original
column vector
11% vecB :
column vector, shape(M,1)
16% B : matrix, shape(M,M)
17% The matrix by which `B\cdot vecA = vecB` holds
19function B = SimilarityMatrixForVectors (vecA, vecB)
21 % construct permutation matrix to move at least one non-zero element to
the first position
22 % to acchieve it,
the code below sorts it in a reverse order
32 % construct transformation matrix B
for which B*rp=1 holds
35 B(i,1:i) = vecB(i) / sum(cp(1:i,1));
37 % construct matrix B
for which B*r=1 holds