Compute the eigenvalues and eigenvectors of a matrix?

Hello all,

I have been having a lot of trouble computing the eigenvalues and eigenvectors of a matrix for a problem that I am working on in computational fluid dynamics. I am new to Mathematica so I am not very familiar with the syntax and I can not find out what is wrong with my code. I have uploaded my script so that you can see how I am trying to compute the eigenvalues and eigenvectors (at the very end of the script). Any help is appreciated, thanks.

Jacobians Eigenvalues and Eigenvectors for 3d Navier Stokes.nb (145 KB)

Your A is not a matrix.

Try

In[30]:= Dimensions[A]

Out[30]= {6, 1, 6, 1}

To compute Eigenvalues you have to have a (square) matrix, that is a list of (one-dimensional) lists.

Look at

In[31]:= m = {{a, b}, {c, d}};
Dimensions[m]
Eigenvalues[m]

Out[32]= {2, 2}

Out[33]= {1/2 (a + d - Sqrt[a^2 + 4 b c - 2 a d + d^2]), 
 1/2 (a + d + Sqrt[a^2 + 4 b c - 2 a d + d^2])}

Why do you write at the beginning

F= { {q2}, ...

putting your variables (?) between { }? That makes q2 to a List.

In[34]:= FullForm[{q2}]

Out[34]//FullForm= \!\(\*
TagBox[
StyleBox[
RowBox[{"List", "[", "q2", "]"}],
ShowSpecialCharacters->False,
ShowStringCharacters->True,
NumberMarks->True],
FullForm]\)

I made a couple of changes in your notebook and arrive at a list of Eigenvalues. Is it that what you meant?

Jacobians Eigenvalues and Eigenvectors for 3d Navier Stokes.nb (125 KB)

Yes, this is exactly what I meant. Sorry, I am really new to mathematica and I was just getting confused with the syntax. I really appreciate your help. Is there any way you could tell me how to compute the eigenvectors as well? What I am trying to do is compute the eigenvectors (hopefully one eigenvector for each eigenvalue) and put them in a matrix where each column is an eigenvector. Does this make sense?

Try

Eigensystem[ matrix ]

That gives you a list. 1st entry is the list of eigenvalues, 2nd entry is a list of Eigenvectors.

And I think you want

Transpose[Eigenvectors[ matrix ] ]

Thank you so much.

Is this correct? I’m having trouble getting output.

Jacobians Eigenvalues and Eigenvectors for 3d Navier Stokes.nb (129 KB)

Well, look at your expressions in matrix A. And A is 6 x 6 - Matrix. It seems to be utmost tedious if not impossible to obtain closed expressions for the eigenvectors. Try to do it numerically.

After quite a time of computation mma comes back with explicit expressions for the Eigenvectors. Note that your systems is four-fold degenerate.

The 1st four Eigenvectors are “simple”, the next two (belonging to the Eigenvlaues with square-root) by far not.

See notebook (at the end).

Jacobians Eigenvalues and Eigenvectors for 3d Navier Stokes _OP_1_CP_.nb (181 KB)

I really appreciate your help, thank you so much. I now know that I will more than likely have to compute these numerically in my Fortran code. Thanks once again

No need to recur to FORTRAN: Just feed numbers in your mma-expression.
E.g.

A1= A/.{gamma->.5, x1x->7, … and so on

You could as well try to find abbreviations for the matrix-elements of A, that could make things easier to handle.

Abbreviations is a good idea, I may try that. I need to eventually put it into fortran because I am working with a computational fluid dynamics solver which is written in fortran. I am trying to let mathematica do the derivation of a physical problem for me so that I can add it to a pre-existing code. Ultimately, the eigenvector calculation will need to be done thousands of times as I step through the CFD solution.

At least you have more or less simple expressions for 4 out of 6 Eigenvectors.

In case you don’t know about it try

FortranForm[ eigenvector ]

I played a bit around with abbreviations in matrix A, but had no real success in making things easier to handle.

I think mma will calculate eignevectors in quite short a time if you feed numbers into matrix A, and as far as I know it is possible to connect mma to Fortran.

Kind regards HD