예제 #1
0
SqMatrix SqMatrix::inverse() const {
	/* Reference: https://chi3x10.wordpress.com/2008/05/28/calculate-matrix-inversion-in-c/ */
	SqMatrix inv(order);
	double det = determinant();
	for (int i=0; i<order; i++) {
		for (int j=0; j<order; j++) {
			inv.arr[j][i] = minorMat(i,j).determinant() * ((i+j)%2 == 1 ? -1.0 : 1.0) / det;
		}
	}
	return inv;
}
예제 #2
0
//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;
}
예제 #3
0
cplxnum CplxMatrix::minor(int row, int col) const{
    return minorMat(row, col).det();
}
예제 #4
0
//recursive call for permenant, ignoring the signs for det
cplxnum CplxMatrix::subperm(int row, int col) const{
    return minorMat(row, col).perm();
}
예제 #5
0
double Matrix::minor(int row, int col) const{
    return minorMat(row, col).det();
}