Skip to content

pancakeswya/SimpleMatrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SimpleMatrix

Implementation of matrix class + bonus template matrix made in stl style.

Matrix operations

There is a brief description of the matrix operations below that need to be implemented in the developing library. They are similar to the operations you performed earlier in «structured programming», so you can see a more detailed description of them there. Note that some operations have exceptional situations that require special handling using the exception mechanism.

Operation Description Exceptional situations
bool EqMatrix(const S21Matrix& other) Checks matrices for equality with each other
void SumMatrix(const S21Matrix& other) Adds the second matrix to the current one different matrix dimensions
void SubMatrix(const S21Matrix& other) Subtracts another matrix from the current one different matrix dimensions
void MulNumber(const double num) Multiplies the current matrix by a number
void MulMatrix(const S21Matrix& other) Multiplies the current matrix by the second matrix the number of columns of the first matrix is not equal to the number of rows of the second matrix
S21Matrix Transpose() Creates a new transposed matrix from the current one and returns it
S21Matrix CalcComplements() Calculates the algebraic addition matrix of the current one and returns it the matrix is not square
double Determinant() Calculates and returns the determinant of the current matrix the matrix is not square
S21Matrix InverseMatrix() Calculates and returns the inverse matrix matrix determinant is 0

Apart from those operations, you also need to implement constructors and destructors:

Method Description
S21Matrix() A basic constructor that initialises a matrix of some predefined dimension
S21Matrix(int rows, int cols) Parametrized constructor with number of rows and columns
S21Matrix(const S21Matrix& other) Copy constructor
S21Matrix(S21Matrix&& other) Move constructor
~S21Matrix() Destructor

And you also need to overload the following operators, partly corresponding to the operations above:

Operator Description Exceptional situations
+ Addition of two matrices different matrix dimensions
- Subtraction of one matrix from another different matrix dimensions
* Matrix multiplication and matrix multiplication by a number the number of columns of the first matrix does not equal the number of rows of the second matrix
== Checks for matrices equality (EqMatrix)
= Assignment of values from one matrix to another one
+= Addition assignment (SumMatrix) different matrix dimensions
-= Difference assignment (SubMatrix) different matrix dimensions
*= Multiplication assignment (MulMatrix/MulNumber) the number of columns of the first matrix does not equal the number of rows of the second matrix
(int i, int j) Indexation by matrix elements (row, column) index is outside the matrix

Usage example

    s21::Matrix mat(4,4);
    mat[0][1] = 1;
    mat(0,2) = 4;
    auto res1 = mat.InverseMatrix();
    // stl style
    s21::matrix<int> mat(5,5);
    mat[0][1] = 5;
    auto res2 = mat.transpose();

About

Implementation of matrix class

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published