Romasmi / cpp-practice

0 stars 0 forks source link

Замечания по InvertMatrix` #6

Closed alexey-malov closed 6 years ago

alexey-malov commented 6 years ago
    Matrix2D invertedMatrix;
    SetAlgebraicComplementMatrix(matrix, invertedMatrix);
    TransposeMatrix(invertedMatrix);
    MatrixByScalar(invertedMatrix, 1 / matrix.definer);
alexey-malov commented 6 years ago
void MatrixByScalar(Matrix2D& matrix, const double scalar)
{
    for_each(matrix.values.begin(), matrix.values.end(), [scalar](vector<double>& row) 
    { 
        for_each(row.begin(), row.end(), [scalar](double& element)
        {
            element *= scalar;
        });
    });
}
alexey-malov commented 6 years ago
void SetMinorMatrix(Matrix2D& matrix, Matrix2D& minorMatrix)
{
    for (unsigned int i = 0; i < matrix.rowsCount; ++i)
    {
        vector<double> subRow;
        for (unsigned int j = 0; j < matrix.colsCount; ++j)
        {
            subRow.push_back(GetMinorOfMatrix(matrix, i, j));
        }
        minorMatrix.values.push_back(subRow);
    }
}
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
void Print2DVector(Matrix2D& matrix)
{
    for_each(matrix.values.begin(), matrix.values.end(), [](vector<double>& row)
    {
        for_each(row.begin(), row.end(), [](double& element)
        {
            cout << element << setprecision(3) << ' ';
        }); 
        cout << "\n";
    });
}
alexey-malov commented 6 years ago
void SetSubMatrix(Matrix2D& matrix, Matrix2D& subMatrix, unsigned int cutRow, unsigned int cutColumn)
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
    for (const MatrixRow row : matrix.values)
    {
        copy(row.begin(), row.end(), ostream_iterator<double>(cout, " "));
        cout << "\n";
    }