simplematrix
pretty simple matrix math library.
How to use
npm install simplematrix
var m = ;// solve AX = Bvar a = 1234;var b = 1110;var x = b;x // Watch out for floating point error/*{ '0': [ -1, -1.9999999999999996 ], '1': [ 1, 1.4999999999999998 ] }*/x // You can round it if you want (casts to precision 12)/*{ '0': [ -1, -2 ], '1': [ 1, 1.5 ] }*/x // But the equals() operator automatically compensates for floating point error/*true*/
Constructors
var a = 1234;var i2 = 2;
Functions on each Matrix
times
Returns the result of multiplying a matrix by a constant or another (correctly-dimensioned) matrix.
var c = a;
plus
var c = a;
equals
Tests for equality. Handles floating point error nicely.
if a
dividedBy
Solves the system of linear equations AX=B via the Gauss-Jordan method with partial pivoting.
var x = b;
inverse
Returns the inverse of a matrix (by letting B equal the identity matrix in a.solve(b)
). The inverse is cached, so if you call .inverse()
a second time, the only work done will be to see if the matrix has changed since the last inverse computation.
var a_inv = a;
transpose
Returns the transpose of a matrix. Not cached.
var a_T = a;
copy
Copies a matrix
var a2 = a;
rounded
Takes care of floating point error using parseFloat(f.toFixed(12))
on each element f of the matrix
var niceMatrix = x;
Properties on each Matrix
rows
var m = arows;
columns
var n = acolumns;