# Homework Help: Matrix diagonalization in c++

1. May 25, 2014

### drake

1. The problem statement, all variables and given/known data
Hi :) I want to write a program in c++ to diagonalize given matrix. However, I'm stuck and I don't have any ideas to do it. I found a linear algebra library for c++ but I could not solve my problem because I don't know how to solve a 2nd order equation. Can you help me please?

2. Relevant equations
How to diagonalize a matrix?

3. The attempt at a solution
This is the library:
http://eigen.tuxfamily.org/index.php?title=Main_Page
this is what diagonalization is:
http://www.math.uconn.edu/~troby/Math2210S14/LT/sec5_3.pdf

2. May 25, 2014

### SteamKing

Staff Emeritus
If by "I don't know how to solve a 2nd order equation" you mean an equation of the second order in the unknown eigenvalue λ, there's formulas for that, too.

It's not clear if you are referring to the characteristic equation of a given matrix, which results from trying to find the eigenvalues by expanding a determinant. While this technique is used often to illustrate some properties of the eigenvalues, most numerical routines don't actually require that the user explicitly form and solve the characteristic equation of a matrix.

And if you are too young to know about how to solve quadratic equations, you're also much too young to be diagonalizing innocent matrices.

3. May 26, 2014

### Staff: Mentor

Using the function that calculates the eigenvalues and eigenvectors, you will get a vector of eigenvalues, which correspond to the diagonal entries in D, and a matrix of eigenvectors, which corresponds to P.

I will humbly disagree with you on that point. I think that a lot of learning and fun can be had working with matrices, even when one hasn't mastered algebra.

To drake: if you just want to play around with matrices, there are easier ways than the approach you are taking. You should get Octave instead, which will be much simpler than using a library in C++.