# Compute the eigenvalues and eigenvectors of a matrix?

**URL:** <https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018>\
**Category:** Questions\
**Tags:** equation-solving, symbolic-computations\
**Created:** [August 27, 2018, 11:08pm UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018 "2018-08-27T23:08:33Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jthress1](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jthress1](https://community.wolfram.com/u/jthress1)\
**Post date:** [August 27, 2018, 11:08pm UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/1 "2018-08-27T23:08:33Z")

</div>

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](https://community.wolfram.com/uploads/short-url/sq16q2NIWDeZXfevehq3GGx2t5v.nb) (145 KB)

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [August 28, 2018, 5:54am UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/2 "2018-08-28T05:54:37Z")

</div>

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]\)

```

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [August 28, 2018, 9:00am UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/3 "2018-08-28T09:00:57Z")

</div>

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](https://community.wolfram.com/uploads/short-url/pakTW3B31YTGrNOQE5ExQoSDURL.nb) (125 KB)

---

<div class="post-metadata">

**Author:** ![jthress1](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jthress1](https://community.wolfram.com/u/jthress1)\
**Post date:** [August 28, 2018, 10:52am UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/4 "2018-08-28T10:52:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [August 28, 2018, 10:58am UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/5 "2018-08-28T10:58:16Z")

</div>

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] ]

---

<div class="post-metadata">

**Author:** ![jthress1](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jthress1](https://community.wolfram.com/u/jthress1)\
**Post date:** [August 28, 2018, 11:16am UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/6 "2018-08-28T11:16:25Z")

</div>

Thank you so much.

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

[Jacobians Eigenvalues and Eigenvectors for 3d Navier Stokes.nb](https://community.wolfram.com/uploads/short-url/wOIgU34C48g0T8rXpfIjKWFJJSQ.nb) (129 KB)

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [August 28, 2018, 12:04pm UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/7 "2018-08-28T12:04:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [August 28, 2018, 12:31pm UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/8 "2018-08-28T12:31:19Z")

</div>

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](https://community.wolfram.com/uploads/short-url/tIIGOF1EDgBWVciPiILHzivE1iU.nb) (181 KB)

---

<div class="post-metadata">

**Author:** ![jthress1](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jthress1](https://community.wolfram.com/u/jthress1)\
**Post date:** [August 28, 2018, 1:11pm UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/9 "2018-08-28T13:11:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [August 28, 2018, 1:30pm UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/10 "2018-08-28T13:30:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jthress1](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jthress1](https://community.wolfram.com/u/jthress1)\
**Post date:** [August 28, 2018, 1:47pm UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/11 "2018-08-28T13:47:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [August 29, 2018, 6:24am UTC](https://community.wolfram.com/t/compute-the-eigenvalues-and-eigenvectors-of-a-matrix/13018/12 "2018-08-29T06:24:02Z")

</div>

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
