apt-get install octave3.2 octave3.2-headers
g++ -c -I/usr/include/octave-3.2.4/octave test.cpp -o test.o mkoctfile --link-stand-alone test.o -o test
g++ -c -I/usr/include/octave-3.2.4/octave -fopenmp test.cpp -o test.o mkoctfile --link-stand-alone -lgomp test.o -o test
Complex number = Complex (0.7, 0.3)
double real( const Complex& z )
double imag( const Complex& z )
// Eigen value // // Last Updated : 2011/06/08 Wed 23:02:56 // #include <iostream> #include <octave/config.h> #include <octave/Matrix.h> using namespace std; int main(int argc, char *argv[]) { Matrix m( 2, 2 ); m( 0, 0 ) = -1; m( 0, 1 ) = -3; m( 1, 0 ) = 0; m( 1, 1 ) = 2; cout << "Original Matrix" << endl << m << endl; EIG eig( m ); cout << "Eigen Vectors" << endl << eig.eigenvectors() << endl; cout << "Eigen Values" << endl << eig.eigenvalues() << endl; cout << "Recomposed Matrix" << endl << eig.eigenvectors() * ComplexMatrix( ComplexDiagMatrix( eig.eigenvalues() ) ) * eig.eigenvectors().inverse() << endl; return 0; }
実行結果
Original Matrix -1 -3 0 2 Eigen Vectors (1,0) (-0.707107,0) (0,0) (0.707107,0) Eigen Values (-1,0) (2,0) Recomposed Matrix (-1,0) (-3,0) (0,0) (2,0)
固有値aを実数部r、虚数部iへ取り出す場合、
ComplexColumnVector a = eig.eigenvalues(); double r = real( a( 0 ) ); double i = imag( a( 0 ) );
Makefile
OPT = -O3 LFLAGS = -lm OCTFLAGS = -I/usr/include/octave-3.2.4/octave OCTLINK = --link-stand-alone GFLAGS = -Wall -g CC = g++ MKOCT = mkoctfile PROGRAM = main OBJS = main.o .c.o: $(CC) $(OPT) $(GFLAGS) $(OCTFLAGS) -c $< all : $(PROGRAM) $(PROGRAM) : $(OBJS) $(MKOCT) $(OCTLINK) $(OBJS) -o $@ clean : rm -f $(OBJS) $(PROGRAM)
参考URL