行列の対角化をしたい


Tips

解説

行列の固有値と固有ベクトルを求めます。

サンプルプログラム

fileeigen1.cpp

#include <iostream>
#include <octave/config.h>
#include <octave/CMatrix.h>
#include <octave/EIG.h>

using namespace std; 

int main()
{
  cout.precision(3);
  cout.setf(ios::fixed);
  Complex const IU(0.0, 1.0);

  int const N = 3; 

  ComplexMatrix A(N, N);
  A(0,0) = 3.0 + IU; A(0,1) = 2.0       ; A(0,2) = IU;     
  A(1,0) = 4.0     ; A(1,1) = 1.0 + IU  ; A(1,2) = 6.0;    
  A(2,0) = 5.0*IU  ; A(2,1) = 3.0 - IU  ; A(2,2) = -4.0*IU;
  
  cout << "originam matrix : A = " << endl << A << endl;
  
  EIG eig(A);
  cout << "Eigen Values " << endl
       << eig.eigenvalues() << endl; 

  ComplexMatrix P = eig.eigenvectors();
  cout << "Eigenvectors : P = " << endl
       << P << endl;
  cout << "P^(-1) * A * P = " << endl 
       << P.inverse() * A * P << endl;
}

出力

originam matrix : A = 
 (3.000,1.000) (2.000,0.000) (0.000,1.000)
 (4.000,0.000) (1.000,1.000) (6.000,0.000)
 (0.000,5.000) (3.000,-1.000) (-0.000,-4.000)

Eigen Values 
(-3.713,0.889)
(6.133,1.289)
(1.580,-4.178) 

Eigenvectors : P = 
 (-0.256,0.076) (0.510,0.060) (-0.347,-0.054)
 (0.832,0.000) (0.790,0.000) (0.106,0.571)
 (-0.482,-0.066) (0.335,-0.002) (0.734,0.000) 

P^(-1) * A * P = 
 (-3.713,0.889) (0.000,-0.000) (0.000,-0.000)
 (-0.000,-0.000) (6.133,1.289) (0.000,0.000)
 (0.000,0.000) (0.000,0.000) (1.580,-4.178)

コメント