1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Matrix diagonalization in c++

  1. May 25, 2014 #1
    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:
    this is what diagonalization is:
  2. jcsd
  3. May 25, 2014 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
  4. May 26, 2014 #3


    User Avatar

    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++.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted