Hi,

I'm trying to find a way to calculate the eigenvalues and eigenvectors for a square symmetrical matrix. I have used MATLAB to do this before and the solution was as simple as;
[V,D] = eig(A)
I'm wondering if there is a simple solution like this in c++. I am aware there is no function to calculate eigensolutions in the c++ math library, but is there an alternative library I can simply "include". I have tried searching the web, and have come across lots of matrix libraries, but I don't understand how to go about using them in my program.

Any help you can offer me would be really appreciated.

Thanks

Recommended Answers

All 5 Replies

I assume the problem you are having is to install the library into your IDE.
What compiler are you using ?

I assume the problem you are having is to install the library into your IDE.
What compiler are you using ?

Hi firstPerson,

Thanks for getting back to me. I'm using Microsoft Visual Studio C++ to compile the program.

The problem is I know matrix libraries exist that can do this but

  1. I don't know what library to use
  2. I don't know how to go about installing a library and then using it in my code

Thanks.

First pick a library, maybe some of these search results. Read up on some and see which one fits you best. After
you have picked a library you will need to install the library into visual studio. You will need to add some directories into visual studio. First
pick a library then worry about installing it.

First pick a library, maybe some of these search results. Read up on some and see which one fits you best. After
you have picked a library you will need to install the library into visual studio. You will need to add some directories into visual studio. First
pick a library then worry about installing it.

I have researched this a bit and I was going to use the NEWMAT library (http://www.robertnz.net/), however if anyone has specific instructions for another library I've no problem using it :)

NEWMAT comes as a zipped file of .h and .cpp files but I don't know what to do with these? how to use them?

Do you need eigenvectors and eigenvalues?
Is your matrix real?
I translated some code into C++. It takes a real symmetric matrix and computes eigenvalues only. It uses the old method of creating dynamic arrays, checking for NULL, which is not the latest and greatest technique, but otherwise the program works:

Eigensystem Solver Code for Real Symmetric Matrix

Alternately, you might want to check out the Boost and NIST TNT
libraries.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.