Doing mathematics with R: Linear algebra in R
Similarity of matrices
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 function rref
that they have the same reduced row echelon form.
> library(pracma)
> A <- matrix(c(4, 2, -2, 1), nrow=2); A
[,1] [,2]
[1,] 4 -2
[2,] 2 1
> B <- matrix(c(3, 1, -2, 2), nrow=2); B
[,1] [,2]
[1,] 3 -2
[2,] 1 2
> rref(A) == rref(B)
[,1] [,2]
[1,] TRUE TRUE
[2,] TRUE TRUE
> all.equal(rref(A), rref(B))
[1] TRUE
> T <- matrix(c(1, 1, -1, 0), nrow=2); T # appropriate transformation matrix
[,1] [,2]
[1,] 1 -1
[2,] 1 0
> inv(T) %*% A %*% T # T^(-1)*A*T is equal to matrix B
[,1] [,2]
[1,] 3 -2
[2,] 1 2
> S <- matrix(c(1, 0, 1, 2), nrow=2); S # transformation matrices are not unique
[,1] [,2]
[1,] 1 1
[2,] 0 2
> B - inv(S) %*% A %*% S
[,1] [,2]
[1,] 0 0
[2,] 0 0
> P <- S %*% inv(T); P # nontrivial transformation matrix that leaves A intact
[,1] [,2]
[1,] -1 2
[2,] -2 2
> A - inv(P) %*% A %*% P
[,1] [,2]
[1,] 0 0
[2,] 0 0
Unlock full access