Beispiel #1
0
//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;
}
Beispiel #2
0
//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;
}
Beispiel #3
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;
}
Beispiel #4
0
cplxnum cplxnum::operator -(const cplxnum& z)
{
	return cplxnum((real - z.real),(img - z.img));
}
Beispiel #5
0
cplxnum cplxnum::operator +(const cplxnum& z)
{ 
	return cplxnum((real + z.real),(img + z.img));
}
Beispiel #6
0
cplxnum cplxnum::conj()
{ 
	return cplxnum(real,-img);
}