For computation of eigenvalues and eigenvectors we use alglib package (version 1.3) which is now part of the CAPD.
Header file
In file
#include "capd/matrixAlgorithms/capd2alglib.h"
there are functions which translate data types between the CAPD and the alglib.
To use alglib with CAPD you need to include only this file .
How to compute eigenvalues?
To compute eigenvalues of given matrix A
A[0][0] = 2; A[0][1] = 10;
A[1][0] = -10; A[1][1] = 2;
first you need to prepare place for output
Remark: Dimensions of rV and iV must be set properly!
Then simply call
and real and imaginary part of eigenvalues will be placed in rV and iV correspondingly.
For convenient output you can use
How to compute eigenvectors?
To compute eigenvectors along with eigenvalues first prepare place for output
and then call
Example
The following example can be found in the capd/examples/alglibdemo directory.
#include "capd/vectalg/lib.h"
#include "capd/matrixAlgorithms/capd2alglib.h"
#include <iostream>
{
A[0][0] = 2; A[0][1] = 10;
A[1][0] = -10; A[1][1] = 2;
std::cout << "\nmatrix A = \n" << A;
}
{
A[0][0] = 5; A[0][1] = 1;
A[1][0] = 3; A[1][1] = 6;
std::cout << "\n======================="
<< "\nmatrix A = \n " << A
std::cout << "\neigenVectors (i-th column contains vector corresponing to i-th eigenvalue)= \n"
<< rVec << "+ i* " << iVec;
std::cout << "\nCHECK (matrix A in the eigenvectors base - should be diagonal up to rounding errors):\n "
}
double data[] = {1, 0, 0,
0, 3, 0,
0, 0, 7};
double base[] = {3, 1, 4,
2, -5, 3,
1, 4, 1};
DMatrix B(3,3, data), P(3,3, base);
std::cout << "\n======================="
<< std::endl;
return 0;
}