Search code examples
sortingwolfram-mathematicaeigenvector

Eigensystem Sort in Wolfram Mathematica


I'm trying to implement in Mathematica a method for analytical solution of reaction kinetics.

Numerically it is not a problem but in a symbolic form, one have to rearrange by hand columns of EigenVectors in order to get the "right" result.

Please check www.biokin.com/tools/pdf/Koro11-Kinetics-Maple-Chap2.pdf, page 41-44 for example.

I'm using a matrix

K={{-k1 - k2, 0, 0, 0}, {k1, 0, 0, 0}, {k2, 0, -k3, k4}, {0, 0, k3, -k4}} 

as pointed out in example on page 43. {vals,vect}=Eigensystem[K] gives a different answer.

As a result my final solution vect.DiagonalMatix[Exp[vals]].Inverse[vect] is a mess.

Is there way to Sort the answer when it is in symbolic form? Or how to "force" Mathematica, not to arrange Eigenvalues and Eigenvectors?


Solution

  • The sorting of Eigenvalues and Eigenvectors is entirely arbitrary, the important part is that that you get the right ones together.

    The issue with your code is that vect is a list of the eigenvectors, which when you use it as a matrix is a matrix whose rows are the eigenvectors, whereas you need a matrix whose columns are the eigenvectors. Use Transpose to fix this. Once you've done this, if you simultaneously permute the eigenvectors and eigenvalues nothing changes:

    randsamp = RandomSample[Range[4]];
    vals[[randsamp]]
    Transpose@vect[[randsamp]].DiagonalMatrix[Exp[vals[[randsamp]] t]].Inverse[
       Transpose@vect[[randsamp]]] // Simplify
    

    Also there is a specific stack exchange site for Mathematica: http://mathematica.stackexchange.com