mathlab
Lodash like math lab in javascript, focusing on matrix manipulation.
Install
Using npm:
$ npm install mathlab --save
Using cdn:
Sample usage
const A = 123 456 const x = 789 // calculate dot product // [50,122]
Features
- Modulize: only import the function you need.
- Easy to use: no extra concepts to grasp(1D Array as vector and 2D Array as matrix)
- Functional: no side effact on input data and the outside world
- Multifunctional: Support
sparse
andcomplex
matrix manipulation;FFT
;eigenvectors & eigenvalues of matrix
; and so on
Introduction to functions
Mathlab provide a collection of mathmatic functions which can be applied to numbers, arrays and two self-defined datatypes (Complex and Sparse).
Functions can be devide into 5 groups:
1. Math Object functions
abs | acos | asin | atan | ceil | cos | exp | floor | log | round | sin | sqrt | tan
The Math object functions have been adapted to work on Arrays, Complex and Sparse Objects
example
// 1 // [1, 2] // {re: 5, im: 0} // {row: col: val:}
2. Arithmetic operations
The standard arithmetic operations have been vectorized:
example
// 3 // [3,4]
3. Linear algebra
dot
example: // [3, 4]
4. Fast Fourier Transforms
example
// {re: [ 15, -5.941, -3.312, -1.688, 0.941], im: [ 40, 0.941, -1.688, -3.312, -5.941]}const fftRes = // {re:[1,2,3,4,5], im:[6,7,8,9,10]}
5. Utility functions
dim
example // [] // [2] // [3,2]
Introduction to Complex and Sparse matrix
Mathlab provided two Classes for you to initialize Complex and Sparse matrix.
Complex
Creates a Complex instance that represents a complex number or array. It accepts two arguments as the real and imaginary part of a complex number or array.
Usage
Initalize
// complex numberconst c = 1 2 // {re:1, im:2} // complex arrayconst ca = 12 12 // {re:[1,2], im:[1,2]} // mathlab functions can be applied on it // {re: [ 1.414, 2.828], im: undefined}
Methods (still adding)
- reciprocal: Pointwise 1/z
- transjugate: The conjugate-transpose of the matrix
ca // {re: [ 0.5, 0.25], im: [ -0.5, -0.25]}
Sparse
Creates a Sparse instance that represents a sparse matrix. In mathlab, sparse matrices are stored in the compressed column storage ordering.
Usage
Initialize
const z = 100520100 // { col: [ 0, 3, 4, 4 ], row: [ 0, 1, 2, 1 ], val: [ 1, 5, 1, 2 ] }
Methods (still adding)
- toFull: Convert to full presentation
z // [[1,0,0],[5,2,0],[1,0,0]]
Thanks
Mathlab start as a refactoring of numeric