m = {{2, 0}, {0, 3}}
some function, say "diagonalize[m]", should just return m.
If I use
diagonalize[m_] := Transpose[Eigenvectors[m]].m.Eigenvectors[m]
it returns {{3, 0}, {0, 2}}. I can certainly write my own routine by
hand, but I thought I'd ask if there's an easy way to ask Mathematica to
preserve the order.
Thanks,
john
On Mon, 31 Oct 2005 grub_s...@yahoo.com wrote:
> I'm trying to diagonalize a matrix in Mathematica, but I need the eigenvalues
> to stay in order. So, for instance, for the initial matrix m,
[snip]
First, how do you specify the order of the eigenvalues, if your matrix is
not diagonal to begin with?
I had the same problem: I un-diagonalized a diagonal matrix with a unitary
matrix in the beginning, used it in the initial conditions to a system of
ODEs, and later had to recover the _changed_ eigenvalues AND eigenvectors
in the same order as put in. (As the eigenvalues were continuous functions
of the variable t, their order made sense.)
I did not find an easy way.
So I:
1) got symbolic expressions for eigenvalues by evaluationg the native
Eigenvalues function for a general matrix of appropriate dimension, e.g.
{{m11,m12},{m21,m22}} in your case);
2) re-ordered the said expressions by evaluating them numerically on the
initial matrix and comparing them to the initial eigenvalues (in correct
order by def.);
3) and made the expressions into a function.
It is not pretty, but it does work.
The eigenvectors I reordered after eigenvalues, of course.
Kristjan Kannike
>I'm trying to diagonalize a matrix in Mathematica, but I need the eigenvalues
>to stay in order. So, for instance, for the initial matrix m,
>
>m = {{2, 0}, {0, 3}}
>
>some function, say "diagonalize[m]", should just return m.
>
>If I use
>
>diagonalize[m_] := Transpose[Eigenvectors[m]].m.Eigenvectors[m]
>
>it returns {{3, 0}, {0, 2}}. I can certainly write my own routine by
>hand, but I thought I'd ask if there's an easy way to ask Mathematica to
>preserve the order.
>
>
Unless you sort the eigenvectors to match the sort you want in your
eigenvectors, I don't think there is functionality in mathematica which
allows to do what you want. You can always use something like
diagonalmatrix[m_?MatrixQ] := DiagonalMatrix[Sort[Part[Eigensystem[m], 1]]]
which I don't think the solution you are looking for
Hope this helps,
Pratik .
>Thanks,
>john
>
>
>
--
Pratik Desai
Graduate Student
UMBC
Department of Mechanical Engineering
Phone: 410 455 8134
>Hello,
>
>On Mon, 31 Oct 2005 grub_s...@yahoo.com wrote:
>
>
>
>>I'm trying to diagonalize a matrix in Mathematica, but I need the eigenvalues
>>to stay in order. So, for instance, for the initial matrix m,
>>
>>
>
>[snip]
>
>First, how do you specify the order of the eigenvalues, if your matrix is
>not diagonal to begin with?
>
>
You don't, but since the eigenvalues are an ordered set of values, they
can always be sorted. The fun actually begins when you have match the
eigenvectors in the unitary matrix to match the eigenvalues. plus if you
have complex eigenvalues, it becomes even more hilarious. :-)
>I had the same problem: I un-diagonalized a diagonal matrix with a unitary
>matrix in the beginning, used it in the initial conditions to a system of
>ODEs, and later had to recover the _changed_ eigenvalues AND eigenvectors
>in the same order as put in. (As the eigenvalues were continuous functions
>of the variable t, their order made sense.)
>
>I did not find an easy way.
>
>So I:
>
>1) got symbolic expressions for eigenvalues by evaluationg the native
>Eigenvalues function for a general matrix of appropriate dimension, e.g.
>{{m11,m12},{m21,m22}} in your case);
>
>2) re-ordered the said expressions by evaluating them numerically on the
>initial matrix and comparing them to the initial eigenvalues (in correct
>order by def.);
>
>3) and made the expressions into a function.
>
>It is not pretty, but it does work.
>
>The eigenvectors I reordered after eigenvalues, of course.
>
>Kristjan Kannike
>
>
>