Skip to content

Latest commit

 

History

History
70 lines (54 loc) · 931 Bytes

README.md

File metadata and controls

70 lines (54 loc) · 931 Bytes

Matrix

Class based implementation of a matrix.

Features

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Uses operator overloading, so you can just plug in the operators (+, -, *) and play

Documentation

Define matrices

vector<vector<int>> mat1 = {{1, 2, 3}, 
                            {6, 5, 4}, 
                            {7, 8, 9}};

vector<vector<int>> mat2 = {{6, 5, 4}, 
                            {7, 8, 9}, 
                            {1, 2, 3}};

Matrix M1(mat1);
Matrix M2(mat2);

Addition

Matrix M3 = M1 + M2;

Result

7  7  7 
13 13 13 
8  10 12

Subtraction

Matrix M4 = M1 - M2;

Result

-5 -3 -1 
-1 -3 -5 
 6  6  6

Multiplication

Matrix M5 = M1 * M2;

Note : Matrix multiplication is an $O(n^3)$ operation.

Print

M5.print();

Result

23  27  31 
75  78  81 
107 117 127