This is a simple matrix library including the following functions:
- Addition
- Subtraction
- Multiplication
- Entrywise multiplication
//Create a matrix object
var matrix = new Matrix([number of row], [number of col]);
//Add value to the matrix
matrix.write(1).write(2).write(3);
//Add all values to the matrix
matrix.writeAll(
1, 2, 3,
4, 5, 6,
7, 8, 9
);
matrix.print(); //Print the matrix
1 2 3
4 5 6
7 8 9
//Transpose
var matrixT = matrix.transpose(); //matrix will not changed.
//Matrix
1 2 3
4 5 6
7 8 9
//MatrixT
1 4 7
2 5 8
3 6 9
//Addition (add) / Subtraction (subtract) / Multiplication (multiply)
//Parameter [Const / Matrix]
matrix.add(3).print(); //Note that the matrix will be updated.
4 5 6
7 8 9
10 11 12
matrix.add(matrixT).print();
5 9 13
9 13 17
13 17 21
//Clone the matrix
var newMatrix = matrix.clone();