#include <numeric.h> int main() { /* eigenvalues of a symmtrical matrix are always real numbers */ array double a[3][3] = {0.8, 0.2, 0.1, 0.2, 0.7, 0.3, 0.1, 0.3, 0.6}; /* eigenvalues of a non-symmtrical matrix can be either real numbers or complex numbers */ /* this non-symmtrical matrix has real eigenvalues */ array double a2[3][3] = {0.8, 0.2, 0.1, 0.1, 0.7, 0.3, 0.1, 0.1, 0.6}; /* this non-symmtrical matrix has complex eigenvalues and eigenvectors*/ array double a3[3][3] = {3, 9, 23, 2, 2, 1, -7, 1, -9}; array double evalues[3],evectors[3][3]; array double complex zevalues[3], zevectors[3][3]; eigen(a, evalues); printf("evalues =\n%f\n", evalues); eigen(a2, evalues); printf("evalues =\n%f\n", evalues); eigen(a2, zevalues, evectors); printf("zevalues =\n%f\n", zevalues); printf("evectors =\n%f\n", evectors); eigen(a3, evalues); printf("evalues =\n%f\n", evalues); eigen(a3, zevalues, zevectors); printf("evalues =\n%f\n", zevalues); printf("evectors =\n%f\n", zevectors); }
evalues = 1.108807 0.652624 0.338569 evalues = 1.000000 0.600000 0.500000 zevalues = complex(1.000000,0.000000) complex(0.600000,0.000000) complex(0.500000,0.000000) evectors = -0.744845 -0.707107 0.408248 -0.579324 0.707107 -0.816497 -0.331042 0.000000 0.408248 evalues = NaN NaN 3.241729 evalues = complex(-3.620864,10.647303) complex(-3.620864,-10.647303) complex(3.241729,0.000000) evectors = complex(0.938908,0.328678) complex(0.938908,-0.328678) complex(0.604364,0.000000) complex(-0.003056,-0.288664) complex(-0.003056,0.288664) complex(0.744064,0.000000) complex(-0.344155,0.899246) complex(-0.344155,-0.899246) complex(-0.284803,0.000000)