Index

Index

jsmatrix.src.js

JavaScript vector and matrix implementation. This file contains JavaScript implementation of vectors and matrices, i.e 1d and 2d arrays of real (floating point) numbers and corresponding mathematical operations. The objects creation is inspired by Numerical Python (numpy) package ( v = JSMatrix.vec([1,2,3]), m = JSMatrix.mat([[1,2,3],[4,5,6],[7,8,9]]) ). The implementation is such that coefficient access can be done directly by a=v[1], v[1]=3., a=m[1][0], m[1][0] = 4. (it is simple and easy, but no dimension is checked), or (in safer but longer way) by get/set method, where dimensions are checked ( a=v.get(1), v.set(1,3.), a=m.get(1,0), m.set(1,0,4.) ). Access function numbering is 0-based(!) (first element has index 0).

When a method returns a new object (e.g. ret = m1.add(m2); ), if operation is successfull (e.g. dimensions agree), the object is returned, if operation fails (e.g. dimensions are mismatched), null value is returned (inspired by Sylvester project).

In vector-matrix context, vectors are considered in their natural representation (row x column vectors). For example in matrix*vector multiplication the vector is considered as 1d column matrix, while in vector*matrix the vector is considered as 1d row matrix (similar approach is used in Mathematica program). In documantation, vectors are considered as 1d column matrices (e.g. vec^T indiceates transposition of vec, i.e. 1d row matrix).

Method naming is usualy following (example is on matrix transposition): verb infinitive (e.g. transpose) is used for function changing receiver - receiver is changed (to its transposition for example) and nothing is returned. Verb past simple (e.g. transposed) is used for function returning new object (transposed copy of receiver for example), receiver is not changed. Names beSomethingOf (e.g. beTranspositionOf) indicates that receiver is modified to become something (transposition of given matrix for example), receiver is changed and given parameter is not. Names isSomething or canSomething (e.g. isTranspositionOf) returns usually bools (true if receiver is transposition of given matrix for example).

Current implementation contains: basic operations (coefficient access, +, -, *, /, +=, -=, *=, vector norms), testing operations, subvector/submatrix operations, solving linear system of equations, eigenvalues and eigenvector solving, matrix decmpositions (LU, LDU, Cholesky, QR, SVD, Schur, spectral, polar) and many others.

For more information see project homepage or further documentation.

JSMatrix is a free software distributed under GNU LGPL license.

Example:
v = new JSMatrix.Vector(); // creates empty vector object
v = new JSMatrix.Vector(4); // creates (zeroed) vector with 4 elements
v = JSMatrix.Vector.create([2,4,3]); // creates vector corresponding to given array (length 3, elements=2,4,3)
a = v[1]; // a = 4.
a[1] = 5.; // sets 5. to a[1]
a[9] = 3.; // sets 3. to a[9] (out of bounds, no error!!)
a.set(9,3.); // sets 3. to a[9], checks bounds, finds that index 9 is out of bounds and does nothing

References:
[1] Quarteroni, A., Sacco, R. and Saleri, F. 2010. Numerical Mathematics, 2nd edition. Springer-Verlag New York
[2] http://en.wikipedia.org/wiki/Matrix_decomposition
[3] Press, W. H., Teukolsky, S. A., Vetterling, W. T. and Flannery, B. P. 2007. The Numerical Recipes: The Art of Scientific Computing, Third Edition
[4] inspiration from Sylvester project
Version:
  • 0.9.dev (2014-08-20)
Author:
  • Jan Stránský <http://mech.fsv.cvut.cz/~stransky>
Source:
  • /var/www/html/software/jsmatrix/jsmatrix.src.js, line 27