Linear mappings: Linear mappings in Python
Similarity
Two matrices are similar if and only if they have the same reduced row echelon form
This means that you can verify in MATLAB similarity of matrices by checking with the command rref
from Symbolic Python (sympy
) package that they have the same reduced row echelon form.
>>> import sympy as sy
>>> sy.init_printing(use_unicode=True) # for pretty printing
>>> A = sy.Matrix([[4, -2], [2, 1]]); A
⎡4 -2⎤
⎢ ⎥
⎣2 1 ⎦
>>> B = sy.Matrix([[3, -2], [1, 2]]); B
⎡3 -2⎤
⎢ ⎥
⎣1 2 ⎦
>>> A.rref() == B.rref()
True
>>> T = sy.Matrix([[1, -1], [1, 0]]); T # appropriate transformation matrix
⎡1 -1⎤
⎢ ⎥
⎣1 0 ⎦
>>> B == T**(-1) * A * T #
True
>>> S = sy.Matrix([[1,1], [0, 2]]); S
⎡1 1⎤
⎢ ⎥
⎣0 2⎦
>>> B == S**(-1) * A * S # transformation matrices are not uniwue
True
>>> P = S * T**(-1); P # non-trivial transformation matrix that leaves A intact
⎡-1 2⎤
⎢ ⎥
⎣-2 2⎦
>>> A == P**(-1) * A * P
True
Unlock full access