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

1. What is matrix diagonalization in c++?

Matrix diagonalization in c++ is a process of finding a diagonal matrix that is similar to a given square matrix. This transformation can simplify certain calculations and make the matrix easier to work with.

2. How is matrix diagonalization performed in c++?

In c++, matrix diagonalization is performed using various algorithms, such as the Jacobi method or the QR method. These algorithms involve a series of operations and transformations on the matrix to reduce it to a diagonal form.

3. Why is matrix diagonalization important in c++?

Matrix diagonalization is important in c++ because it allows for easier computation and analysis of certain properties of a matrix. It can also help in solving systems of linear equations and finding eigenvalues and eigenvectors.

4. Can any matrix be diagonalized in c++?

Not all matrices can be diagonalized in c++. For a matrix to be diagonalizable, it must have a full set of linearly independent eigenvectors. If the matrix does not have this property, it cannot be diagonalized.

5. Are there any limitations to matrix diagonalization in c++?

One limitation of matrix diagonalization in c++ is that it can be computationally expensive for large matrices. Additionally, in some cases, the diagonalized form of a matrix may not be unique, leading to different diagonal matrices that are similar to the given matrix.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
18
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
Replies
4
Views
3K
  • Precalculus Mathematics Homework Help
Replies
32
Views
833
  • Precalculus Mathematics Homework Help
Replies
25
Views
979
  • Calculus and Beyond Homework Help
Replies
1
Views
1K
  • Calculus and Beyond Homework Help
Replies
11
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • Calculus and Beyond Homework Help
Replies
2
Views
382
  • Linear and Abstract Algebra
Replies
1
Views
2K
Back
Top