Prev | Up | Next

Notice: These methods are no longer supported as the algorithm used here is not always converging for medium to large size matrices.

Eigen value and eigen vector

The following methods are available to evaluate the eigen values and corresponding eigen vectors of a matrix.

1. bool eigen (valarray<T>& reival) const;
2. bool eigen (valarray<T>& reival, matrix<T>& eivec) const;

3. bool eigen (valarray<T>& reival, valarray<T>& ieival) const;
4. bool eigen (valarray<T<& reival, valarray<T>& ieival, matrix<T>& eivec) const;

Parameter

reival
Reference to a valarray class object to receive the real eigen values of a matrix.
ieival
Reference to a valarray class object to receive the imaginary eigen values of a matrix.
eivec
Reference to a matrix class object to receive the eigen vectors of a matrix.

  1. Finds the eigen values of a symmetric matrix. If successful, the eigen values are copied into the valarray class object reival, and this method returns true, otherwise, it returns false.


  2. Finds the eigen values and eigen vectors of a symmetric matrix. If successful, the eigen values are copied into the valarray class object reival and corresponding eigen vectors into matrix eivec, and this method returns true, otherwise, it returns false.


  3. Finds the eigen values of a general square matrix. If successful, the real eigen values are copied into reival and imaginary eigen values into ieival, and this method returns true, otherwise, it returns false.


  4. Finds the eigen values and eigen vectors of a general square matrix. If successful, the real eigen values are copied into reival, imaginary eigen values into ieival, and corresponding eigen vectors into eivec, and this method returns true, otherwise, it returns false.


Examples
typedef techsoft::matrix<double> Matrix;
typedef std::valarray<double> Vector;

using techsoft::gmslice;
using techsoft::LTRIANG;
using techsoft::UTRIANG;

size_t n = 4;
Matrix a(n,n), ev(n,n);
Vector d(n), e(n);
bool ret;

a.rand();
a = a[gmslice(UTRIANG)];
a[gmslice(LTRIANG)] = ~a;       // a is now a symmetric matrix

ret = a.eigen( d);              // Finds the eigen values
ret = a.eigen( d, ev);          // Finds both eigen values and eigen vectors

a.rand();
ret = a.eigen( d, e);           // Finds real and imaginary eigen values
ret = a.eigen( d, e, ev);       // Finds real and imaginary eigen values and eigen vectors