# How do I tell if matrices are similar?

I have two $2\times 2$ matrices, $A$ and $B$, with the same determinant. I want to know if they are similar or not.

I solved this by using a matrix called $S$: $$\left(\begin{array}{cc} a& b\\ c& d \end{array}\right)$$ and its inverse in terms of $a$, $b$, $c$, and $d$, then showing that there was no solution to $A = SBS^{-1}$. That worked fine, but what will I do if I have $3\times 3$ or $9\times 9$ matrices? I can't possibly make system that complex and solve it. How can I know if any two matrices represent the "same" linear transformation with different bases?

That is, how can I find $S$ that change of basis matrix?

I tried making $A$ and $B$ into linear transformations... but without the bases for the linear transformations I had no way of comparing them.

(I have read that similar matrices will have the same eigenvalues... and the same "trace" --but my class has not studied these yet. Also, it may be the case that some matrices with the same trace and eigenvalues are not similar so this will not solve my problem.)

I have one idea. Maybe if I look at the reduced col. and row echelon forms that will tell me something about the basis for the linear transformation? I'm not really certain how this would work though? Please help.

• Your question has different answers depending on what kind of matrices you allow. Are $A$ and $B$ real matrices? Do you care if $S$ is allowed to be complex or not? unitary/orthogonal or not, etc.. Dec 12, 2010 at 20:50

There is something called "canonical forms" for a matrix; they are special forms for a matrix that can be obtained intrinsically from the matrix, and which will allow you to easily compare two matrices of the same size to see if they are similar or not. They are indeed based on eigenvalues and eigenvectors.

At this point, without the necessary machinery having been covered, the answer is that it is difficult to know if the two matrices are the same or not. The simplest test you can make is to see whether their characteristic polynomials are the same. This is necessary, but not sufficient for similarity (it is related to having the same eigenvalues).

Once you have learned about canonical forms, one can use either the Jordan canonical form (if the characteristic polynomial splits) or the rational canonical form (if the characteristic polynomial does not split) to compare the two matrices. They will be similar if and only if their rational forms are equal (up to some easily spotted differences; exactly analogous to the fact that two diagonal matrices are the same if they have the same diagonal entries, though the entries don't have to appear in the same order in both matrices).

The reduced row echelon form and the reduced column echelon form will not help you, because any two invertible matrices have the same forms (the identity), but need not have the same determinant (so they will not be similar).

• "The simplest test you can make is to see whether their characteristic polynomials are the same. This is necessary, but not sufficient for similarity (it is related to having the same eigenvalues)." - To illustrate, look at $$\bigl(\begin{smallmatrix}1&0\\0&1\end{smallmatrix}\bigr)$$ and $$\bigl(\begin{smallmatrix}1&1\\0&1\end{smallmatrix}\bigr)$$ ; they have the same characteristic polynomial, but are definitely not similar (the latter is a defective matrix, not having a complete eigenvector set). Dec 13, 2010 at 1:00
• In the realm of inexact arithmetic, the Jordan decomposition cannot be stably computed (since the similarity transformations required can be arbitrarily ill-conditioned), and in its place, the Schur decomposition (which uses orthogonal/unitary similarity transformations) is used. Dec 13, 2010 at 1:02
• @J.M. Good point, and good illustration. Dec 13, 2010 at 1:05
• @J.M. The fact that the Jordan decomposition cannot be stably computed numerically implies that in the realm of inexact arithmetic similarity of matrices cannot be decided, period. Not using Jordan normal forms, nor using any other method. Because nilpotent matrices are similar if and only if they have the same JNF; if you cannot determine the JNF of $A$, you cannot decide whether $A$ is similar to a candidate JNF matrix. Jun 9, 2014 at 11:43
• [continued] Which is not surprising, since in that realm even equality of matrices cannot be decided (nor, I am tempted to add, can anything at all be decided). If one is interested in approximate similarity (matrices can be made similar by a small perturbation) then is suffices to test the characteristic polynomials for approximate equality. Because in each class of matrices with a given characteristic polynomial$~\chi$, the similarity class of generic ones (those as non-diagonalisable as possible given$~\chi$) is dense. Jun 9, 2014 at 12:00

My lecturer, Dr. Miryam Rossett, provided the following in her supplementary notes to her linear 1 course ( with a few small additions of my own ):

1. Show that the matrices represent the same linear transformation according to different bases. This is generally hard to do.
2. If one is diagonalizable and the other not, then they are not similar.
3. Examine the properties of similar matrices. Do they have the same rank, the same trace, the same determinant, the same eigenvalues, the same characteristic polynomial. If any of these are different then the matrices are not similar.
4. Check the geometric multiplicity of each eigenvalue. If the matrices are similar they must match. Another way of looking at this is that for each $$\lambda_i$$, $$\dim \ker(\lambda_i I-A_k)$$ must be equal for each matrix. This also implies that for each $$\lambda_i$$, $$\dim \text{im}(\lambda_i I-A_k)$$ must be equal since $$\dim \text{im}+\dim \ker=\dim V$$
5. Assuming they're both diagonalizable, if they both have the same eigenvalues then they're similar because similarity is transitive. They'e diagonalizable if the geometric multiplicities of the eigenvalues add up to $$\dim V$$, or if all the eigenvalues are distinct, or if they have $$\dim V$$ linearly independent eigenvectors.

Numbers 3 and 4 are necessary but not sufficient for similarity.

• tr(A) can also be found from the sum of the eigenvalues. Oct 15, 2012 at 11:24

First off, the $2\times2$ case is easy: two distinct $2\times2$ matrices are similar if and only if they have the same characteristic polynomial, and neither of them is a scalar matrix (multiple of the identity). This is essentially because for such small matrices the characteristic polynomial leaves very little room for variation of the minimal polynomial (and other invariant factors that in this case follow from it).

There is a decision method that works in full generality (any field$~K$, any size$~n$ square matrices) and is theoretically simple: compute the invariant factors by determining the Smith normal form of the matrices $XI_n-A$ and $XI_n-B$ (those whose determinants define the respective characteristic polynomials) as matrices with polynomials in$~X$ as entries; then $A$ and $B$ are similar if and only if identical lists of invariant factors are found.

With "theoretically simple" I mean the method only uses basic operations in$~K$ you might be expected to perform: arithmetic of scalars and testing for equality; notably it does not require finding roots or factoring polynomials as any method based on eigenvalues would do. Essentially the Smith normal form algorithm is a generalisation of Gaussian elimination, but working over a PID rather than over a field (which here means: doing polynomial operations on polynomial entries, rather than just using scalars), and allowing column operations as well as row operations. The final goal is to reduce the matrix to its Smith normal form, which has nonzero (polynomial) entries only on the main diagonal, and which are monic polynomials such that each one divides the next (in general there could also be trailing zeros, but that does not happen here since our initial matrices have monic, therefore nonzero, determinants). The diagonal entries found that are different from$~1$ are the invariant factors of $A,B$ respectively; the last one is the minimal polynomial and their product is the characteristic polynomial. Those two polynomials can of course also be computed by other methods, and if either of them differs between $A$ and $B$ this suffices to show they are not similar; in the (rather rare) general case however all invariant factors are needed. In most cases there will be many diagonal entries$~1$, followed by one or very few non-constant polynomials that are the invariant factors.

Being theoretically simple does not mean the procedure is easy to perform (by hand), as it is like in iterated version of the Euclidean algorithm in the ring $K[X]$ of polynomials, which algorithm is notable for producing very complicated intermediate results, at least when $K=\Bbb Q$ (and over $\Bbb R$ or $\Bbb C$ the algorithm isn't really effective, as testing for equality is not accurately possible). It works fine over finite fields though.

• I like the answer, but it does seem a bit level inappropriate for the OP. For instance I suspect the OP would not know what a PID is. Jun 9, 2014 at 11:15
• @TimSeguine If you ask for a question that is above your grade, you can expect an answer that is above your grade. The question of similarity of matrices cannot be solved in general using only the tools of a first course in linear algebra. But if you are interested only in having an effective procedure, the algorithm for the Smith normal form is very similar to Gaussian elimination, and you only need PID theory to understand why it decides similarity. And there is no really light-weight decision procedure for similarity, that's just too bad. Jun 9, 2014 at 11:33
• Fair enough. I only meant that I think it could be phrased a bit more accessibly. It's possible to explain how to compute the Smith normal form with less technical language. Jun 9, 2014 at 11:37
• @TimSeguine: I've tried to tone down the language a bit. But I don't really think OP cares; (s)he seems to have left this site more than a year before I first posted this answer ;-) Jun 9, 2014 at 12:33

A simple proof that matrices $A=\begin{bmatrix}1 & 0\\0 & 1\end{bmatrix}$ and $B=\begin{bmatrix}1 & 1\\0 & 1\end{bmatrix}$ stated above as a counterexample are not similar.

If they were, then $B=P^{-1}AP$ for an invertible $2 \times 2$ matrix $P$. But $A=I$ and, therefore, $B=P^{-1}AP=P^{-1}IP=I$, which is a contradiction.

If you have two specific matrices, A and B, here is a method that will work. It's messy, but it will work for any two matrices, regardless of size. First, rewrite the similarity equation in the form AS=SB, where S is a matrix of variables. Multiply out both matrices to obtain a set of n-squared linear equations in n-squared unknowns. Solve the system using Gaussian-Jordan elimination. You need to use the form of the Gaussian-Jordan algorithm that produces matrices in row-echelon form when there is no single solution to the system. The system of equations always has a solution, the zero matrix. If the Gaussian-Jordan elimination produces a single solution, the matrices are not similar. If there is more than one solution, the row-echelon matrix can be solved for a set of basis vectors of the solution space. Since the constant terms are all zero, any matrix generated by the basis vectors is a similarity matrix for A and B.

• I don't think this method always works. It is quite possible that the subspace of solutions is nonzero but consists entirely of singular matrices. Since the determinant is not a linear form on the vector space of square matrices, I don't think it is even easy to see whether it takes nonzero values anywhere on the solution subspace. Apr 12, 2014 at 8:45
• @MarcvanLeeuwen I think you are right to be cautious. However, since invertibility is generic (the set of singular matrices has measure zero), if we found a singular matrix solution, there should be a non singular matrix in a neighborhood around that.The argument is heuristic perhaps (and not constructive), but I think it is at least reasonable. Jun 9, 2014 at 11:09
• @TimSeguine Old comment, but $S=0$ satisfies the equation and tells us nothing. But anyway, abstractly you can parameterize the subspace of solutions with some free variables. Now compute the determinant of $S$ as a function of those free variables. We need that determinant to not be identically zero. Over an infinite field, this happens if and only if the determinant as a formal multivariate polynomial is zero. So, over infinite exact fields this should give a generic algorithm. May 27, 2021 at 3:51

Here is a MATLAB .m function that computes a real similarity matrix for two real matrices known to be similar http://deadbeatjeff.sdf.org/Scripts/transitionjeff.m, implementing the algorithm from the answer https://math.stackexchange.com/a/639369/329781 above. It uses the randsoln.m function (which possibly depends on other .m functions) in Joel Robbin's .m functions .zip file corresponding to his book Matrix Algebra Using MINimal MATlab; the .zip file can be found here and here. My .m function takes a while to run but is factually accurate.

This .m function http://deadbeatjeff.sdf.org/Scripts/transitionDiagJeff.m uses diagonalization to compute the transition matrix but 1) will likely fail if the Jordan normal form of the two matrices is not a diagonal matrix and 2) will likely produce a similarity matrix that is imaginary if the similar matrices have an imaginary eigenvalue.

Here is a script to test the function http://deadbeatjeff.sdf.org/Scripts/test.m