Creates real() method + corrects Matrix operator* method
This commit is contained in:
parent
91cd9b20de
commit
3555f675d0
Modules/Matrix
@ -157,7 +157,7 @@ Matrix Matrix::operator*(Matrix const &matrix) const
|
||||
|
||||
else
|
||||
{
|
||||
Matrix result(m_lines, m_columns);
|
||||
Matrix result(m_lines, matrix.m_columns);
|
||||
|
||||
for(int i(0); i < m_lines; i++)
|
||||
{
|
||||
@ -165,7 +165,7 @@ Matrix Matrix::operator*(Matrix const &matrix) const
|
||||
{
|
||||
for(int k(0); k < m_columns; k++)
|
||||
{
|
||||
result.m_tab[i][j] += matrix.m_tab[i][k] * m_tab[k][j];
|
||||
result.m_tab[i][j] += m_tab[i][k] * matrix.m_tab[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -271,6 +271,20 @@ double Matrix::innerProduct(Matrix const& other) const
|
||||
}
|
||||
}
|
||||
|
||||
double Matrix::real() const
|
||||
{
|
||||
if (m_lines==1 && m_columns==1)
|
||||
{
|
||||
return m_tab[0][0];
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
cout<< "Cannot convert matrix with format "<<m_lines<<"x"<<m_columns<<" into a real number."<<endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ostream& operator<<(ostream &out, Matrix const &matrix)
|
||||
{
|
||||
|
@ -47,6 +47,7 @@ class Matrix
|
||||
bool operator==(Matrix const&) const;
|
||||
bool operator!=(Matrix const&) const;
|
||||
double innerProduct(Matrix const&) const;
|
||||
double real() const;
|
||||
|
||||
void displayMatrix(std::ostream&) const;
|
||||
void deallocate(void);
|
||||
|
Reference in New Issue
Block a user