For computation of eigenvalues and eigenvectors we use alglib package (version 1.3) which is now part of the CAPD.
Header file
In file
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
void computeEigenvalues(const MatrixT &A, VectorT &eigenRealPart, VectorT &eigenImPart)
Function computes Eigenvalues of a general matrix.
Definition: capd2alglib.h:32
and real and imaginary part of eigenvalues will be placed in rV and iV correspondingly.
For convenient output you can use
std::string eigenvaluesToString(const VectorType &re, const VectorType &im, std::string separator=", ")
Converts vector of eigenvalues to text (string)
Definition: capd2alglib.h:158
How to compute eigenvectors?
To compute eigenvectors along with eigenvalues first prepare place for output
and then call
void computeEigenvaluesAndEigenvectors(const MatrixT &A, VectorT &eigenRealPart, VectorT &eigenImPart, MatrixT &vectorRealPart, MatrixT &vectorImPart)
Computes Eigenvalues and corresponding right Eigenvectors.
Definition: capd2alglib.h:79
Example
The following example can be found in the capd/examples/alglibdemo directory.
#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;
}
std::string eigenvectorsToString(const MatrixType &re, const MatrixType &im, std::string separator=", ", std::string vectorSeparator=",\n")
Converts eigenvectors stored as columns of matrices to text (string)
Definition: capd2alglib.h:183
int main(int argc, char *argv[])
Definition: argdemo.cpp:81
MatrixType gaussInverseMatrix(const MatrixType &A)
Definition: floatMatrixAlgorithms.hpp:748
Definition: ApplicationDesc.h:23