Package Exports
- vectorious
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vectorious) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Vectorious
Vectorious is a generalized n-dimensional matrix and vector library written in JavaScript, which can be used both in node.js and the browser.
Clone or install with
$ npm install vectoriousUsage
The constructors of both Matrix and Vector are designed to be flexible, so they can be initialized using several different arguments.
var vectorious = require('vectorious');
var vector,
matrix;
vector = new vectorious.Vector();
// { values: [], length: 0 }
matrix = new vectorious.Matrix();
// { rows: [] }
vector = new vectorious.Vector().zeros(5);
// { values: [0, 0, 0, 0, 0], length: 5 }
vector = new vectorious.Vector(1, 2, 3, 4, 5);
// { values: [1, 2, 3, 4, 5], length: 5 }
matrix = new vectorious.Matrix(vector);
// { rows: [ { values: [1, 2, 3, 4, 5], length: 5 } ] }
matrix = new vectorious.Matrix().zeros(2, 2);
/* {
rows: [
{ values: [0, 0], length: 2 },
{ values: [0, 0], length: 2 }
]
} */
var input = [
[1, 2],
[3, 4]
];
matrix = new vectorious.Matrix(input);
/* {
rows: [
{ values: [1, 2], length: 2 },
{ values: [3, 4], length: 2 }
]
} */Matrix
The following matrix operations and methods are implemented in matrix.js.
// (Matrix, Matrix) => (Matrix)
Matrix.prototype.add = function(matrix)Add two matrices together.
// (Matrix, Matrix) => (Matrix)
Matrix.prototype.subtract = function(matrix)Subtract two matrices.
// (Matrix, Number) => (Matrix)
Matrix.prototype.scale = function(scalar)Multiply all elements in matrix with a scalar.
// (Matrix, Matrix) => (Matrix)
Matrix.prototype.multiply = function(matrix)Multiply two matrices together.
// (Matrix) => (Matrix)
Matrix.prototype.transpose = function()Transpose a matrix.
// (Matrix, Boolean) => (Matrix)
Matrix.prototype.gauss = function(reduce)Convert a matrix to (reduced) row echelon form.
// (Matrix) => (Vector)
Matrix.prototype.diag = function()Get matrix diagonal as a Vector.
// (Matrix, Matrix) => (Matrix)
Matrix.prototype.augment = function(matrix)Create an augmented matrix.
// (Matrix) => (Number)
Matrix.prototype.trace = function()Get matrix trace (the sum of the diagonal).
// (Matrix, Number) => (Matrix)
Matrix.prototype.identity = function(size)Create an identity matrix.
// (Matrix, Number, Number) => (Matrix)
Matrix.prototype.zeros = function(i, j)Create an i x j matrix of zeros.
// (Matrix, Number, Number) => (Matrix)
Matrix.prototype.ones = function(i, j)Create an i x j matrix of ones.
// (Matrix, Matrix) => (Boolean)
Matrix.prototype.equals = function(matrix)Compare two matrices.
// (Matrix, Number, Number) => (Number)
Matrix.prototype.get = function(i, j)Get element at row i, column j.
// (Matrix, Number, Number, Number) => (Matrix)
Matrix.prototype.set = function(i, j, value)Set the value of an element at row i, column j.
// (Matrix, Number, Number) => (Matrix)
Matrix.prototype.swap = function(i, j)Swaps the position of rows i and j.
// (Matrix, Function) => (Matrix)
Matrix.prototype.map = function(callback)Maps a function callback to all elements of the matrix.
// (Matrix) => (String)
Matrix.prototype.toString = function()Convert matrix to string.
Vector
The following vector operations and methods are implemented in vector.js.
// (Vector, Vector) => (Vector)
Vector.prototype.add = function(vector)Add two vectors together.
// (Vector, Vector) => (Vector)
Vector.prototype.subtract = function(vector)Subtract two vectors.
// (Vector, Number) => (Vector)
Vector.prototype.scale = function(scalar)Multiply a vector by a scalar.
// (Vector) => (Vector)
Vector.prototype.normalize = function()Normalize a vector.
// (Vector, Vector) => (Number)
Vector.prototype.dot = function(vector)Get dot product of two vectors.
// (Vector) => (Number)
Vector.prototype.magnitude = function()Get magnitude of vector (Pythagoras).
// (Vector, Vector) => (Angle)
Vector.prototype.angle = function(vector)Get the angle (in radians) between two vectors.
// (Vector, Vector) => (Vector)
Vector.prototype.project = function(vector)Project a vector onto another vector.
// (Vector, Number) => (Vector)
Vector.prototype.zeros = function(count)Create a vector of count zeros.
// (Vector, Number) => (Vector)
Vector.prototype.ones = function(count)Create a vector of count ones.
// (Vector, Number, [Number], Number) => (Vector)
Vector.prototype.range = function(start, [step], end)Create a vector containing the range from start to end in steps of step (optional).
// (Vector, Vector) => (Boolean)
Vector.prototype.equals = function(vector)Compare two vectors.
// (Vector, Number) => (Number)
Vector.prototype.get = function(index)Get value of an element at index.
// (Vector, Number, Number) => (Vector)
Vector.prototype.set = function(index, value)Set value of an element at index.
// (Vector, Function) => (Vector)
Vector.prototype.map = function(callback)Maps a function callback to all elements of the vector.
// (Vector) => (String)
Vector.prototype.toString = function()Convert vector to string.
Todo
- Add testing suite
- Add more useful operations :)
Contribute
Feel free to fork and commit pull requests. If you have any problems just submit an issue or send me an email.