//Permenant of a matrix cplxnum CplxMatrix::perm() const{ if (r != c) { std::cout<<"incompatible shapes"<<std::endl; return cplxnum(); } if (r == 0) return cplxnum(); if (r == 1) return el(0,0); cplxnum result; for (int dem = 0; dem < r; dem++) { result = result + el(0,dem)*(subperm(0, dem)); } return result; }
//Determinant is implemented using recursive calls cplxnum CplxMatrix::det() const{ if (r != c) { std::cout<<"incompatible shapes"<<std::endl; return cplxnum(); } if (r == 0) return cplxnum(); if (r == 1) return el(0,0); cplxnum result; for (int dem = 0; dem < r; dem++) { result = result + ((dem%2==0)?(1):(-1))*el(0,dem)*(minor(0, dem)); } return result; }
//A bad revursive implementation of diagnol minor, a better way could be using permutations/combinations to select the //rows/columns cplxnum CplxMatrix::diagonalMinor(int level) const{ cplxnum result; if (r != c) { std::cout<<"incompatible shapes"<<std::endl; return cplxnum(); } if (level <= 0) { std::cout<<"invalid level specification"<<std::endl; return result; } if (level == 1) { for (int i = 0; i < r; i++) { result = result + minor(i, i); } return result; } for (int i = 0; i < r; i++) { result = result + (1/double(level))*minorMat(i, i).diagonalMinor(level - 1); } return result; }
cplxnum cplxnum::operator -(const cplxnum& z) { return cplxnum((real - z.real),(img - z.img)); }
cplxnum cplxnum::operator +(const cplxnum& z) { return cplxnum((real + z.real),(img + z.img)); }
cplxnum cplxnum::conj() { return cplxnum(real,-img); }