SMatrix SMatrix::trans() const { SMatrix newMat; newMat.setRows(cols); newMat.setCols(rows); for( int i = 0; i < cols; i++ ) { for( int j = 0; j < rows; j++ ) { newMat.setVal(i, j, data[j][i]); } } return newMat; }
SMatrix SMatrix::scale(int scalar) const { SMatrix newMat; newMat.setRows(rows); newMat.setCols(cols); int result; for( int i = 0; i < rows; i++ ) { for( int j = 0; j < cols; j++ ) { result = scalar * data[i][j]; newMat.setVal(i, j, result); } } return newMat; }
SMatrix add(const SMatrix& m1, const SMatrix& m2) { SMatrix newMat; newMat.setRows(m1.getRows()); newMat.setCols(m1.getCols()); int result; for( int i = 0; i < m1.getRows(); i++ ) { for( int j = 0; j < m1.getCols(); j++ ) { result = m1.valAt(i+1, j+1) + m2.valAt(i+1, j+1); newMat.setVal(i, j, result); } } return newMat; }
SMatrix SMatrix::minus(const SMatrix& otherMat) const { SMatrix newMat; newMat.setRows(rows); newMat.setCols(cols); int result; for( int i = 0; i < rows; i++ ) { for( int j = 0; j < cols; j++ ) { result = data[i][j] - otherMat.valAt(i+1, j+1); newMat.setVal(i, j, result); } } return newMat; }
SMatrix SMatrix::times(const SMatrix& otherMat) const { SMatrix newMat; newMat.setRows(rows); newMat.setCols(otherMat.getCols()); int result; for( int i = 0; i < rows; i++ ) { for( int k = 0; k < otherMat.getCols(); k++ ) { result = 0; for(int j = 0; j < otherMat.getRows(); j++ ) { result+=(data[i][j] * otherMat.valAt(j+1, k+1)); } newMat.setVal(i, k, result); } } return newMat; }