I have a template class and I would like to get the determinant of a given matrix. The class can do the methods with complex numbers too.I defined the complex class and there are no errors in it.

Here is my class.

{
 template<class T = double>
class Matrix
{
private:
unsigned row;
unsigned column;
T **matrix;
template<class OUTP>
friend std::ostream& operator<<(std::ostream&, const Matrix<OUTP>&);
template<class INP>
friend std::istream& operator>>(std::istream&, Matrix<INP>&);
public:
Matrix(unsigned = 0, unsigned = 0);
~Matrix();
Matrix(const Matrix<T>&);
void setMatrixElment(unsigned, unsigned, T);
void delMatrix();
unsigned getRow()const { return row; }
unsigned getColumn()const { return column; }
T getElement(unsigned = 0, unsigned = 0);
Matrix<T>& operator=(const Matrix<T>&);
Matrix<T> operator+(const Matrix<T>&);
Matrix<T> operator-(const Matrix<T>&);

Matrix <T>inverz();
bool open1();
bool open2();
    Matrix<T> operator*(const double&);
Matrix<T> operator*(const Matrix<T>&);
T determinant() const;

}


}

This was my method

{

  template<class T>
 T Matrix<T>::determinant() const 
try {
    if (column != row)
    {
        throw "not zero";
    }
    T d = 1;
    for (unsigned k = 0; k < column; k++)
    {
        for (unsigned i = k + 1; i < column; i++)
        {
            T g = (matrix[i][k] / matrix[k][k]);

            for (unsigned j = k + 1; j < column; j++)
            {
                matrix[i][j] = matrix[i][j] - g * 
                                                             matrix[k][j];
            }
        }
        d = d * matrix[k][k];
    }
    return d;

}
catch (...)
{
    cerr << "the matrix is not a square matrix" << endl;
}


}

I expected a number.The debugger shows no errors but in the output i see this (for a 3*3 matrix)

 {       
        Matrix<Complex> b1;
        bool nyit1 = true;
        Matrix<Complex> a1;
        nyit1 = a1.open1();
        if (!nyit1)
            cout << "Hibas megnyitas." << endl;
        b1 = a1;
        b1 << cout // here shows me a 3x3 matrix
        b1.determinant; // here is the using of the method


 }

output:

1+(2)*i   3+(4)*i   5+(6)*i

7+(8)*i   9+(1)*i   2+(3)*i

4+(5)*i   6+(7)*i   8+(9)*i
:18.6
14.8
30.2
21.6
10.8
9.4
17.6
13.8
1
2
9.25596e+61
9.25596e+61
-9.25596e+61
2.77679e+62
-6.85383e+124
3.42691e+124
}

0 Answers