Haimasker / Complex-numbers-matrix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Complex numbers matrix

Simple C++ implementation of complex numbers matrix using vector of vectors from std.

GitHub code size in bytes Number of lines of code Code language count GitHub top language


Preamble

The purpose of this project is to create Matrix class that will be helpful in future projects.
Matrix is presented via std::vector<> of std::vector<> of std::complex<> of double


Class fields

All of Matrix class fields are private

  1. rows - number of rows in matrix
unsigned rows;
  1. cols - number of columns in matrix
unsigned cols;
  1. mat - matrix of elements (rows x cols sized)
std::vector<std::vector<std::complex<double>>> mat;

Constructors and destructor

  1. The Constructor receiving the number of rows, cols and initial value for elements.
    By default have values 0, 0 and 0+0i respectively.
Matrix(unsigned = 0, unsigned = 0, std::complex<double> = 0.0 + 0.0i);

  1. The constructor receiving a vector that represents a matrix.
    Vector should be square.
Matrix(std::vector<std::vector<std::complex<double>>>*);

  1. The constructor receiving the number of rows, cols, vector that represents a matrix and initial value for elements.
    Makes rows x cols sized matrix, fills it elementwise from given vector.
    If there are not enough elements in the given vector, then fills remaining elements with initial value.
Matrix(unsigned, unsigned, std::vector<std::vector<std::complex<double>>>*, std::complex<double> = 0.0 + 0.0i);

  1. The constructor receiving the number of rows, cols, vector of elements and initial value for elements.
    Makes rows x cols sized matrix, fills it elementwise from given vector.
    If there are not enough elements in the given vector, then fills remaining elements with initial value.
Matrix(unsigned, unsigned, std::vector<std::complex<double>>*, std::complex<double> = 0.0 + 0.0i);

  1. Copy constructor
Matrix(const Matrix&);

  1. Destructor
virtual ~Matrix();

Operators

  1. Call operator for non-const objects receiving row and col.
    Returns mat[row][col].
    Indices are cycled, so there is no out-of-range error
std::complex<double>& operator () (const unsigned&, const unsigned&);

  1. Call operator for const objects receiving row and col.
    Returns mat[row][col].
    Indices are cycled, so there is no out-of-range error
const std::complex<double>& operator () (const unsigned&, const unsigned&) const;

  1. Copy assignment operator.
Matrix& operator = (const Matrix&);

  1. Addition operator.
    Sums matrices elementwise.
Matrix operator + (const Matrix&);

  1. Addition assignment operator.
    Sums matrices elementwise.
Matrix& operator += (const Matrix&);

  1. Subtraction operator.
    Subtracts matrices elementwise.
Matrix operator - (const Matrix&);

  1. Subtraction assignment operator.
    Subtracts matrices elementwise.
Matrix& operator -= (const Matrix&);

  1. Multiplication operator.
    Multiplies matrices elementwise.
Matrix operator * (const Matrix&);

  1. Multiplication assignment operator.
    Multiplies matrices elementwise.
Matrix& operator *= (const Matrix&);

  1. Assignment operator.
    Assigns matrix elements to given value.
Matrix& operator = (const std::complex<double>&);

  1. Addition operator.
    Sums matrix elements with given value.
Matrix operator + (const std::complex<double>&);

  1. Addition assignment operator.
    Sums matrix elements with given value.
Matrix& operator += (const std::complex<double>&);

  1. Subtraction operator.
    Subtracts given value from matrix elements.
Matrix operator - (const std::complex<double>&);

  1. Subtraction assignment operator.
    Subtracts given value from matrix elements.
Matrix& operator -= (const std::complex<double>&);

  1. Multiplication operator.
    Multiplies matrix elements by given value.
Matrix operator * (const std::complex<double>&);

  1. Multiplication assignment operator.
    Multiplies matrix elements by given value.
Matrix& operator *= (const std::complex<double>&);

  1. Division operator.
    Divides matrix elements by given value.
Matrix operator / (const std::complex<double>&);

  1. Division assignment operator.
    Divides matrix elements by given value.
Matrix& operator /= (const std::complex<double>&);

  1. Equal operator.
    Determines if matrices are equal.
bool operator == (const Matrix&);

  1. Non-equal operator.
    Determines if matrices are not-equal.
bool operator != (const Matrix&);

  1. Output operator.
    Prints matrix to output.
friend std::ostream& operator << (std::ostream&, const Matrix&);

Methods

  1. elementwiseProduct
    Multiplies this->mat by given matrix elementwise.
void elementwiseProduct(const Matrix&);

  1. elementwiseProduct
    Returns elementwise product of given matrices.
static Matrix elementwiseProduct(const Matrix&, const Matrix&);

  1. elementwiseDivision
    Divides this->mat by given matrix elementwise.
void elementwiseDivision(const Matrix&);

  1. elementwiseDivision
    Return elemetwise division of given matrices.
static Matrix elementwiseDivision(const Matrix&, const Matrix&);

  1. conjugate
    Transforms elements of this->mat to it's conjugate.
void conjugate();

  1. conjugate
    Returns conjugate of given matrix.
static Matrix conjugate(const Matrix&);

  1. transpose
    Transposes this->mat.
void transpose();

  1. transpose
    Returns transposition of given matrix.
static Matrix transpose(const Matrix&);

  1. hermitianConjugate
    Transform this->mat to it's Hermitian-conjugate.
void hermitianConjugate();

  1. hermitianConjugate
    Returns Hermitian-conjugate of given matrix.
static Matrix hermitianConjugate(const Matrix&);

  1. tensorProduct
    Produces a tensor product with the given matrix.
void tensorProduct(const Matrix&);

  1. tensorProduct
    Returns tensor product of given matrices.
static Matrix tensorProduct(const Matrix&, const Matrix&);

  1. cofactor
    Returns false if matrix is not square.
    Returns true and transforms this->mat to it's co-factor matrix if matrix is square.
bool cofactor();

  1. adjugate
    Returns false if matrix is not square.
    Returns true and transforms this->mat to it's adjugate matrix if matrix is square.
bool adjugate();

  1. inverse
    Returns false if matrix is not square.
    Returns true and transforms this->mat to it's inverse matrix if matrix is square.
bool inverse();

  1. resize
    Receive row, col and initial value init.
    Resizes matrix to row x col.
    If matrix becomes greater (in any dimension), then new empty elements are filled with init value.
void resize(const unsigned&, const unsigned&, const std::complex<double>& = 0.0 + 0.0i);

  1. reshape
    Returns false if reshaping is impossible.
    Returns true and reshapes this->mat if it is possible.
bool reshape(const unsigned&, const unsigned&);

  1. trace
    Returns trace of matrix.
std::complex<double> trace();

  1. determinant
    Returns 0+0i if matrix is not square.
    Returns determinant of matrix if it is square.
std::complex<double> determinant();

  1. identity
    Returns identity matrix with given size.
static Matrix identity(const unsigned& = 1);

  1. getRows
    Returns rows value.
unsigned getRows();

  1. getCols
    Returns cols value.
unsigned getCols();

About


Languages

Language:C++ 100.0%