Diagonalizing Matrices in C++: A Beginner's Guide

In summary, the person is asking for help with writing a program in C++ to diagonalize a matrix and is stuck because they do not know how to solve a second order equation. They have found a linear algebra library but are unsure of how to use it and are asking for clarification on diagonalization. The response suggests using a function that calculates eigenvalues and eigenvectors as a simpler approach.
  • #1
drake
30
2

Homework Statement


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?


Homework Equations


How to diagonalize a matrix?


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
 
Physics news on Phys.org
  • #2
drake said:

Homework Statement


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?


Homework Equations


How to diagonalize a matrix?


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

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


SteamKing said:
I
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.
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++.
 

Similar threads

Replies
1
Views
4K
Replies
11
Views
3K
Replies
14
Views
4K
Replies
7
Views
8K
Replies
1
Views
2K
Back
Top