# Matrix - library for Arduino matrix calculation!

```  Matrix.h - A free library for matrix calculation. Invalid dimension for calculation
will lead to empty matrix, therefore, one should check whether the matrix is
empty after calculation.

This library is easy to use, I have overloaded operators, one can use +,*,/,-,
=,==,!= as they want, but there is no definition for matrix division (like A/B).
One should use the inverse function inv() instead.

The transpose() and inv() functions are static functions, which should use
Matrix<Type>::transpose() and Matrix<Type>::inv() format to call, Type is the
type you used to create the matrix.

Feedback and contribution is welcome!

Version 1.2
* Now it can perform mixed calculation with scalars. But you need to ensure the dimension of the matrix is 1 for plus and minus.

Version 1.1
* Improved the processing speed. It becomes very efficient.
-----------------
Version 1.0

Created by Yudi Ren, Jan 05, 2018.
renyudicn@outlook.com
```

# FEATURES

This library supports c++ template, which means you could use any type you want. Here we use word "Any" to represent the type. At first, you have to create the instance of the matrix as shown below:

```Matrix<Any> A();  //create an empty matrix
Matrix<Any> B(2,2);  //create a 2 by 2 matrix with all elements are zero
Matrix<Any> C(5,2,5);   //create a 5 by 2 matrix with all elements equal 5
Matrix<Any> D(4,4,'I');   //create a 4 by 4 identity matrix, it has to be a square matrix,
//otherwise it creates an empty matrix
Any array[3][4] = {{1,2,3,10},{4,5,6,11},{7,8,9,12}};
Matrix<Any> E(3,4,(Any*)array); //create a 3 by 4 matrix and initialise it by the array
Matrix<Any> D(E);  //copy the matrix E
```

Note you HAVE to cast the array into (Any*) type if you want to use an array to initialise it.

This library is easy to use, I have overloaded operators, one can use +,*,/,-, =,==,!= as they want, but there is no definition for matrix division (like A/B). One should use the inverse function inv() instead.

This library also provides functions for transpose, inverse, swap row, display and to check whether the matrix is empty or not:

```static Matrix inv(const Matrix & A); //The inverse function uses the Gauss-Jordan
//Elimination,it won't modify the original matrix and it returns the inverse of  matrix A
static Matrix transpose(const Matrix & A);  //The transpose function won't modify the original matrix and it returns the transpose of matrix A
void swapRow(int i, int j);  //i: the row needs to be swaped, j: the position the row i goes to, this function modifies the original matrix
void show(int decimal = 0);  //decimal: the numbers of decimal place
bool notEmpty();  //check if it's an empty matrix.
```

The transpose() and inv() functions are static functions, which should use Matrix<Any>::transpose() and Matrix<Any>::inv() format to call. See the example for more information.

# How to install

The source is on GitHub, unzip the source code and then place it in the library folder of Arduino. Refer to https://forum.arduino.cc/index.php?topic=88380.0 for more information.

After this step, you could open a new Arduino IDE window, from the menu bar "File->Examples->Matrix->matrix_example" to use the example.