Class Matrix

Nested Relationships

Nested Types

Class Documentation

class Matrix

Class representing a mathematical matrix.

Public Functions

Matrix(int rows, int cols)

Constructs a new matrix of the given dimensions

Parameters
  • rows – Number of rows

  • cols – Number of columns

Matrix(std::initializer_list<std::initializer_list<double>> matrixData)

Constructs a new matrix with the given data

Parameters

matrixData – matrix data

Matrix(std::vector<std::vector<double>> matrixData)

Constructs a new matrix with the given data

Parameters

matrixData – matrix data

Matrix(std::vector<MatrixRow> matrixData)

Constructs a new matrix with the given data

Parameters

matrixData – matrix data

Matrix(const Matrix &other)

Constructs a new matrix that is a copy of the given matrix

Parameters

other – The Matrix to be copied

MatrixRow &operator[](int i)

Operator to get a reference to the row at the specified index

Parameters

i – The index of the row to return

Throws

std::invalid_argument – if the index does not exist

Returns

A reference to the row at the specified index

const MatrixRow &operator[](int i) const

Operator to get a const reference to the row at the specified index

Parameters

i – The index of the row to return

Throws

std::invalid_argument – if the index does not exist

Returns

A const reference to the element at the specified index

Vector getCol(int i)

Gets a specified column vector of the matrix

Parameters

i – The index of the column vector to return

Throws

std::invalid_argument – if the index does not exist

Returns

The column vector at the specified index

Vector getRow(int i)

Gets a specified row vector of the matrix

int rows() const

Gets the number of rows of the matrix

Returns

number of rows of the matrix

int cols() const

Gets the number of columns of the matrix

Returns

number of columns of the matrix

Matrix transpose()

Returns the transpose of the matrix

double norm()

Calculates the frobenius norm of the matrix

double det()

Calculates the determinant of the matrix using the Laplace expansion

Throws

std::invalid_argument – if the matrix is not square

Matrix minor(int i, int j)

Computes the i,j minor of the matrix

double cofactor(int i, int j)

Computes the i,j cofactor of the matrix

Matrix inverse()

Computes the matrix inverse using the adjoint matrix

std::string toString()

Returns a string representation of the matrix