行列の指数関数を求めたい


Tips

解説

正方行列Aの指数関数exp(A)を求めます。 MatrixまたはComplexMatrixのexpm()メソッドを使います。

サンプルプログラム

filematrix_exp.cpp

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

using namespace std;

int main()
{
  cout.precision(3);
  cout.setf(ios::fixed);

  int const N = 4;
  Complex const IU(0.0, 1.0);

  ComplexMatrix m(N, N);
  m(0,0) = 3.0 + IU; m(0,1) = 2.0       ; m(0,2) = IU     ; m(0,3) = -IU;
  m(1,0) = 4.0     ; m(1,1) = 1.0 + IU  ; m(1,2) = 6.0    ; m(1,3) = 2.0;
  m(2,0) = 5.0*IU  ; m(2,1) = 3.0 - IU  ; m(2,2) = -4.0*IU; m(2,3) = -3.0;
  m(3,0) = -2.0    ; m(3,1) = 1.0-5.0*IU; m(3,2) = 3.0    ; m(3,3) = -1.0+IU;
 
  cout << "original matrix m" << endl;
  cout << m << endl;

  cout << "exp(m) = " << endl << m.expm() << endl;
}

出力

original matrix m
 (3.000,1.000) (2.000,0.000) (0.000,1.000) (-0.000,-1.000)
 (4.000,0.000) (1.000,1.000) (6.000,0.000) (2.000,0.000)
 (0.000,5.000) (3.000,-1.000) (-0.000,-4.000) (-3.000,0.000)
 (-2.000,0.000) (1.000,-5.000) (3.000,0.000) (-1.000,1.000)

exp(m) = 
 (14.099,157.884) (44.466,53.726) (45.018,21.440) (16.650,3.707)
 (100.837,348.395) (132.215,104.035) (118.377,27.711) (36.296,4.819)
 (-8.179,174.032) (43.382,67.119) (49.924,30.706) (15.955,6.811)
 (256.033,9.725) (103.378,-66.367) (47.175,-75.042) (11.387,-20.617)

コメント