Skip to content

AbelVM/av.matrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

av.matrix

av.matrix is a small & fast JavaScript matrix (2D arrays) utilities library. Pure, strict and ECMAScript 5 compliant.

It extends the core Array object to supply the basics for linear Algebra (2D), in a clean, compact and speedy way where the explicit loops have been avoided. But LU()... :(

Can be combined with [av.array] (https://github.com/AbelVM/av.arrays "Small&Fast Javascript library that attaches xtra methods for arrays, including basic Descriptive Statistics functions") to get even more from your matrix!

Being arrX a Matrix:

  • Constructors: A matrix can be instatiated using a wide variety of inputs:
arrA = new Matrix();					// [0]
arrB = new Matrix(n);				//	Zero row vector size n
arrC = new Matrix(1,m);			// Zero column vector size m
arrD = new Matrix(n,m);			// Zero matrix size n x m

r1 = [E11,...,E1m] ;
...
rn = [En1,..., Enm];
arrE = new Matrix(r1, ..., rn);			//  nxm matrix with the given rows

arrF = new Matrix([[], ..., []]);		// Matrix from the given array of arrays (rows)	

arrG = Matrix.Fill(n, value);				// Square matrix size = n, every item = value
arrH = Matrix.Diagonal (n, value);	// Diagonal matrix size = n,  item(i=j) = value
arrI = Matrix.Upper(n, value);			// Upper matrix size n,  item(i>=j)  = value
arrJ = Matrix.Lower(n, value);			// Lower matrix size n,  item(i<=j)  = value
  • Algebra methods: Here is where fun begins:
arrB = arrA.scalar(value);				// New matrix, where scalar multiplication of value has been applied to arrA
arrD = arrA.add(arrC);					// New matrix that results of the sum of ArrA and ArrB, both of the same size. 
arrF = arrA.dot(arrE);					// New matrix, dot product of arrA and arrE, where size of arrA is axb and size of arrE is bxc
arrA.LU();										// Object with the matrices resulting of the LU decomposition of arrA. {"L":arrL , "U": arrU}
arrA.det();									// Returns the determinant of arrA
arrG = arrA.adjugate();					// New matrix, adjugate of arrA
arrH = arrA.inverse();					// New matrix, inverse of arrA

####And several support methods!

  • Properties:
Matrix.version;								// String with [av.matrix] version (read-only)
arrA.size;										// Array [n,m] with the size n x m of the matrix (read-only)
arrA.trace;									// Number, the trace of the matrix (read-only)
  • Retrievers
arrA.item(i,j);								// Returns the value of item(i,j)
arrA.row(i);									// Returns an array with the values of row i
arrA.column(j);								// Returns an array with the values of column j
  • Checking methods: Perform some usual checks to matrices:
arrA.samesize(arrB);						// True if both matrices have the same size
arrA.is(arrB);								// True if arrA == ArrB
arrA.isNaN();									// Trueif arrA has at least one NaN item 
arrA.symmetric();							// True if arrA is symmetric. item(i,j)==item(j,i)
arr.square();									// True if arrA is an square matrix
  • Process methods: Methods that apply simple process to the current Matrix:
arrB = arrA.fill(value);						// New matrix with the same size as arrA but filled with value
arrC = arrA.upper();							// New matrix, same as arrA, but item(i<j)  = 0
arrD = arrA.lower();							// New matrix, same as arrA, but item(i>j)  = 0
arrE = arrA.transpose();						// New matrix, transpose of arrA. 
arrF = arrA.minor(i,j);						// New matrix, size n-1 x m-1. Minor of itemA(i,j)
  • Xtra methods:
arrB = arrA.clone();							// New matrix, deep clone of arrA
arrA.tostring(sep);								// Pretty print of arrA, using sep as separator of items (default sep= ', ')

About

av.matrix is a small & fast JavaScript matrix (2D arrays) utilities library. Pure, strict and ECMAScript 5 compliant.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published