TMatrix
TMatrix
for (int r = 0; r < m_Rows; r++) {
for (int c = 0; c < m_Cols; c++) {
if ( (r + c) % 2 ) m(c, r) = -1 * this->SubMatrixEx(r, c).Det();
else m(c, r) = this->SubMatrixEx(r, c).Det();
}
}
return m;
}
// 计算当前矩阵的逆矩阵,当前矩阵须为n阶方阵
TMatrix
ElemType det = this->Det();
TMatrix
return adj * (1 / det);
}
public:
ElemType operator()(int row, int col) const { return m_Elems[row * m_Cols + col];};
ElemType& operator()(int row, int col) { return m_Elems[row * m_Cols + col]; }
public:
// 两矩阵相加,必须具有相同的行数以及列数
TMatrix
TMatrix mr(this->m_Rows, this->m_Cols);
for(int r = 0; r < this->m_Rows; r++) {
for(int c = 0; c < this->m_Cols; c++) {
mr(r, c) = (*this)(r, c) + m(r, c);
}
}
return mr;
} // operator+(const TMatrix& m) const
// 两矩阵相减,必须具有相同的行数以及列数
TMatrix
TMatrix mr(this->m_Rows, this->m_Cols);
for(int r = 0; r < this->m_Rows; r++) {
for(int c = 0; c < this->m_Cols; c++) {
mr(r, c) = (*this)(r, c) - m(r, c);
}
}
return mr;
} // operator-(const TMatrix& m) const
// 矩阵与常数相乘(数乘)
TMatrix
TMatrix mr(this->m_Rows, this->m_Cols);
for(int r = 0; r < this->m_Rows; r++) {
for(int c = 0; c < this->m_Cols; c++) {
mr(r, c) = (*this)(r, c) * v;
}
}
return mr;
} // operator*(ElemType v) const
// 矩阵相乘(当前矩阵列数须等于参数矩阵的列数),
// 结果矩阵行数等于当前矩阵,列数等于参数矩阵的列数
TMatrix
TMatrix mr(this->m_Rows, m.m_Cols);
for (int r = 0; r < this->m_Rows; r++) {
for (int c = 0; c < m.m_Cols; c++) {
for (int i = 0; i < this->m_Cols; i++) {
mr(r, c) += ( (*this)(r, i) * m(i, c) );
printf("(%d, %d)\n", r, c);
}
}
}
return mr;
} // operator*(const TMatrix& m) const
}; // class TMatrix
} // namespace matical
#endif // MATICAL_TMATRIX_H_INCLUDED