Reputation: 337
I'm considering a matrix A such that A=PDP^-1.
The way I solve this using Mathematica is:
a={{0, -1}, {-1, 0}}
d = DiagonalMatrix[Eigenvalues[a]]
{{-1,0}, {0,1}}
p = Transpose[Eigenvectors[a]]
p.d.Inverse[p]
{{0, -1}, {-1, 0}}
Which is correct.
Problem is, the P matrix is not what I expected it to be. The matrix that Mathematica generates is
p={{1, -1}, {1, 1}}
But I am looking for
p2={{1/Sqrt[2], 1/Sqrt[2]}, {1/Sqrt[2], -(1/Sqrt[2])}}
p2.d.Inverse[p2]
{{0,-1}, {-1,0}}
Which also solves the equation. Is there a way for me to force Mathematica to show me different answers when executing Transpose[Eigenvectors[a]]?
Upvotes: 6
Views: 38060
Reputation: 4964
Perhaps you should consider a built in matrix factorization tool? Of course, there are many matrix factorizations, many of which are built in to Mathematica. The one that likely corresponds most closely to your situation is JordanDecomposition
. Here it is in action
SeedRandom[1];
a = RandomReal[{-2, 2}, {4, 4}];
{s, j} = JordanDecomposition[a];
Column[MatrixForm /@ {s, j}]
Chop[s.j.Inverse[s] - a]
Of course, many matrices are not diagonalizable but, if it is, then the Jordan decomposition will give you what you want. The vectors are normalized in the same way that the Eigen
functions normalize them, but I fail to see why this is a problem.
Upvotes: 2
Reputation: 10627
What you need to do is normalize the answer you get. There is a function called Normalize, which can be used like this:
Normalize /@ {{1, -1}, {1, 1}}
Upvotes: 11
Reputation: 131710
Eigenvectors can be freely rescaled by a constant, which means there are an infinite number of possible eigenvectors. Naturally, Mathematica cannot and will not show you all of them. So you'll need to normalize the eigenvectors in some way.
One option is to convert your matrix to numeric form using N
. Mathematica returns normalized eigenvectors for numeric matrices.
p2 = Transpose[Eigenvectors[N[a]]]
This is risky, though, because computing the inverse of a numeric matrix can often fail spectacularly due to various numerical errors.
The other, better option is to manually normalize the eigenvectors using Normalize
. You'll have to apply it to each eigenvector in the list returned by the Eigenvectors
function:
p2 = Transpose[Normalize/@Eigenvectors[a]]
Upvotes: 4
Reputation: 6520
You could normalize your eigenvectors:
a = {{0, -1}, {-1, 0}};
d = DiagonalMatrix[Eigenvalues[a]];
p = Transpose[Normalize /@ Eigenvectors[a]];
so p
is what you want:
{{1/Sqrt[2], -(1/Sqrt[2])}, {1/Sqrt[2], 1/Sqrt[2]}}
Upvotes: 5