EigenJS
The goal of this project is to port Eigen library into JavaScript for linear algebar.
Installation
- OS X (XCode & Command Line Tools)
- Linux (GCC >= 4.8):
$ npm install eigenjs
- Windows7/8 (Visual Studio 2012):
$ npm install eigenjs --msvs_version=2012
API
- Complex
- Complex Class Methods
- Complex(real, [imag])
- Complex.polar(scalar, scalar)
- Complex.cos(scalar)
- Complex.cos(comp)
- Complex.cosh(scalar)
- Complex.cosh(comp)
- Complex.exp(scalar)
- Complex.exp(comp)
- Complex.log(scalar)
- Complex.log(comp)
- Complex.log10(scalar)
- Complex.log10(comp)
- Complex.pow(scalar, scalar)
- Complex.pow(scalar, comp)
- Complex.pow(comp, scalar)
- Complex.pow(comp, comp)
- Complex.sin(scalar)
- Complex.sin(comp)
- Complex.sinh(scalar)
- Complex.sinh(comp)
- Complex.sqrt(scalar)
- Complex.sqrt(comp)
- Complex.tan(scalar)
- Complex.tan(comp)
- Complex.tanh(scalar)
- Complex.tanh(comp)
- Complex.acos(scalar)
- Complex.acos(comp)
- Complex.acosh(scalar)
- Complex.acosh(comp)
- Complex.asin(scalar)
- Complex.asin(comp)
- Complex.asinh(scalar)
- Complex.asinh(comp)
- Complex.atan(scalar)
- Complex.atan(comp)
- Complex.atanh(scalar)
- Complex.atanh(comp)
- Complex Instance Methods
- comp.abs()
- comp.arg()
- comp.norm()
- comp.conj()
- comp.proj(scalar)
- comp.proj(comp)
- comp.add(scalar)
- comp.add(comp)
- comp.adda(scalar)
- comp.adda(comp)
- comp.sub(scalar)
- comp.sub(comp)
- comp.suba(scalar)
- comp.suba(comp)
- comp.mul(scalar)
- comp.mul(comp)
- comp.mul(mat)
- comp.mul(vec)
- comp.mul(rvec)
- comp.mul(mblock)
- comp.mul(vblock)
- comp.mul(rvblock)
- comp.mul(cmat)
- comp.mul(cvec)
- comp.mul(crvec)
- comp.mul(cmblock)
- comp.mul(cvblock)
- comp.mul(crvblock)
- comp.mula(scalar)
- comp.mula(comp)
- comp.div(scalar)
- comp.div(comp)
- comp.diva(scalar)
- comp.diva(comp)
- comp.equals(scalar)
- comp.equals(comp)
- comp.isApprox(comp, [prec = 1e-12])
- comp.toString()
- Complex Properties
- Complex Class Methods
- Matrix
- Matrix Class Methods
- Matrix(mat)
- Matrix(vec)
- Matrix(rvec)
- Matrix(mblock)
- Matrix(vblock)
- Matrix(rvblock)
- Matrix(rows, cols)
- Matrix.Zero(n)
- Matrix.Zero(rows, cols)
- Matrix.Ones(n)
- Matrix.Ones(rows, cols)
- Matrix.Constant(rows, cols, scalar)
- Matrix.Constant(rows, cols, comp)
- Matrix.Random(n)
- Matrix.Random(rows, cols)
- Matrix.Identity(n)
- Matrix.Identity(rows, cols)
- Matrix Instance Methods
- mat.rows()
- mat.cols()
- mat.set(row, col, scalar)
- mat.set(scalar_array)
- mat.get(row, col)
- mat.assign(mat)
- mat.assign(vec)
- mat.assign(rvec)
- mat.assign(mblock)
- mat.assign(vblock)
- mat.assign(rvblock)
- mat.value()
- mat.setZero()
- mat.setOnes()
- mat.setConstant(scalar)
- mat.setRandom()
- mat.setIdentity()
- mat.setDiagonal(index, vec)
- mat.setDiagonal(index, rvec)
- mat.block(startRow, startCol, blockRows, blockCols)
- mat.row(n)
- mat.col(n)
- mat.topRows(n)
- mat.bottomRows(n)
- mat.middleRows(startRow, n)
- mat.leftCols(n)
- mat.rightCols(n)
- mat.middleCols(startCol, n)
- mat.topLeftCorner(cRows, cCols)
- mat.topRightCorner(cRows, cCols)
- mat.bottomLeftCorner(cRows, cCols)
- mat.bottomRightCorner(cRows, cCols)
- mat.replicate(rowFactor, colFactor)
- mat.add(mat)
- mat.add(vec)
- mat.add(rvec)
- mat.add(mblock)
- mat.add(vblock)
- mat.add(rvblock)
- mat.add(cmat)
- mat.add(cvec)
- mat.add(crvec)
- mat.add(cmblock)
- mat.add(cvblock)
- mat.add(crvblock)
- mat.adda(mat)
- mat.adda(vec)
- mat.adda(rvec)
- mat.adda(mblock)
- mat.adda(vblock)
- mat.adda(rvblock)
- mat.sub(mat)
- mat.sub(vec)
- mat.sub(rvec)
- mat.sub(mblock)
- mat.sub(vblock)
- mat.sub(rvblock)
- mat.sub(cmat)
- mat.sub(cvec)
- mat.sub(crvec)
- mat.sub(cmblock)
- mat.sub(cvblock)
- mat.sub(crvblock)
- mat.suba(mat)
- mat.suba(vec)
- mat.suba(rvec)
- mat.suba(mblock)
- mat.suba(vblock)
- mat.suba(rvblock)
- mat.mul(scalar)
- mat.mul(comp)
- mat.mul(mat)
- mat.mul(vec)
- mat.mul(rvec)
- mat.mul(mblock)
- mat.mul(vblock)
- mat.mul(rvblock)
- mat.mul(cmat)
- mat.mul(cvec)
- mat.mul(crvec)
- mat.mul(cmblock)
- mat.mul(cvblock)
- mat.mul(crvblock)
- mat.mula(scalar)
- mat.mula(mat)
- mat.mula(vec)
- mat.mula(rvec)
- mat.mula(mblock)
- mat.mula(vblock)
- mat.mula(rvblock)
- mat.div(scalar)
- mat.div(comp)
- mat.diva(scalar)
- mat.transpose()
- mat.conjugate()
- mat.adjoint()
- mat.determinant()
- mat.inverse()
- mat.trace()
- mat.diagonal([index = 0])
- mat.norm()
- mat.redux(func)
- mat.sum()
- mat.prod()
- mat.mean()
- mat.visit(func)
- mat.maxCoeff()
- mat.maxCoeff(obj)
- mat.maxCoeff(func)
- mat.minCoeff()
- mat.minCoeff(obj)
- mat.minCoeff(func)
- mat.equals(mat)
- mat.equals(vec)
- mat.equals(rvec)
- mat.equals(mblock)
- mat.equals(vblock)
- mat.equals(rvblock)
- mat.isApprox(mat, [prec = 1e-12])
- mat.isApprox(vec, [prec = 1e-12])
- mat.isApprox(rvec, [prec = 1e-12])
- mat.isApprox(mblock, [prec = 1e-12])
- mat.isApprox(vblock, [prec = 1e-12])
- mat.isApprox(rvblock, [prec = 1e-12])
- mat.isSquare()
- mat.isZero([prec = 1e-12])
- mat.isOnes([prec = 1e-12])
- mat.isIdentity([prec = 1e-12])
- mat.isDiagonal([prec = 1e-12])
- mat.all()
- mat.any()
- mat.count()
- mat.allFinite()
- mat.hasNaN()
- mat.partialPivLu()
- mat.fullPivLu()
- mat.toString([options])
- Matrix Class Methods
- Complex Matrix
- Complex Matrix Class Methods
- CMatrix(mat)
- CMatrix(vec)
- CMatrix(rvec)
- CMatrix(mblock)
- CMatrix(vblock)
- CMatrix(rvblock)
- CMatrix(cmat)
- CMatrix(cvec)
- CMatrix(crvec)
- CMatrix(cmblock)
- CMatrix(cvblock)
- CMatrix(crvblock)
- CMatrix(rows, cols)
- CMatrix.Zero(n)
- CMatrix.Zero(rows, cols)
- CMatrix.Ones(n)
- CMatrix.Ones(rows, cols)
- CMatrix.Constant(rows, cols, scalar)
- CMatrix.Constant(rows, cols, comp)
- CMatrix.Random(n)
- CMatrix.Random(rows, cols)
- CMatrix.Identity(n)
- CMatrix.Identity(rows, cols)
- Complex Matrix Instance Methods
- cmat.rows()
- cmat.cols()
- cmat.set(row, col, comp)
- cmat.set(comp_array)
- cmat.get(row, col)
- cmat.assign(mat)
- cmat.assign(vec)
- cmat.assign(rvec)
- cmat.assign(mblock)
- cmat.assign(vblock)
- cmat.assign(rvblock)
- cmat.assign(cmat)
- cmat.assign(cvec)
- cmat.assign(crvec)
- cmat.assign(cmblock)
- cmat.assign(cvblock)
- cmat.assign(crvblock)
- cmat.value()
- cmat.setZero()
- cmat.setOnes()
- cmat.setConstant(scalar)
- cmat.setConstant(comp)
- cmat.setRandom()
- cmat.setIdentity()
- cmat.setDiagonal(index, vec)
- cmat.setDiagonal(index, rvec)
- cmat.setDiagonal(index, cvec)
- cmat.setDiagonal(index, crvec)
- cmat.block(startRow, startCol, blockRows, blockCols)
- cmat.row(n)
- cmat.col(n)
- cmat.topRows(n)
- cmat.bottomRows(n)
- cmat.middleRows(startRow, n)
- cmat.leftCols(n)
- cmat.rightCols(n)
- cmat.middleCols(startCol, n)
- cmat.topLeftCorner(cRows, cCols)
- cmat.topRightCorner(cRows, cCols)
- cmat.bottomLeftCorner(cRows, cCols)
- cmat.bottomRightCorner(cRows, cCols)
- cmat.replicate(rowFactor, colFactor)
- cmat.add(mat)
- cmat.add(vec)
- cmat.add(rvec)
- cmat.add(mblock)
- cmat.add(vblock)
- cmat.add(rvblock)
- cmat.add(cmat)
- cmat.add(cvec)
- cmat.add(crvec)
- cmat.add(cmblock)
- cmat.add(cvblock)
- cmat.add(crvblock)
- cmat.adda(mat)
- cmat.adda(vec)
- cmat.adda(rvec)
- cmat.adda(mblock)
- cmat.adda(vblock)
- cmat.adda(rvblock)
- cmat.adda(cmat)
- cmat.adda(cvec)
- cmat.adda(crvec)
- cmat.adda(cmblock)
- cmat.adda(cvblock)
- cmat.adda(crvblock)
- cmat.sub(mat)
- cmat.sub(vec)
- cmat.sub(rvec)
- cmat.sub(mblock)
- cmat.sub(vblock)
- cmat.sub(rvblock)
- cmat.sub(cmat)
- cmat.sub(cvec)
- cmat.sub(crvec)
- cmat.sub(cmblock)
- cmat.sub(cvblock)
- cmat.sub(crvblock)
- cmat.suba(mat)
- cmat.suba(vec)
- cmat.suba(rvec)
- cmat.suba(mblock)
- cmat.suba(vblock)
- cmat.suba(rvblock)
- cmat.suba(cmat)
- cmat.suba(cvec)
- cmat.suba(crvec)
- cmat.suba(cmblock)
- cmat.suba(cvblock)
- cmat.suba(crvblock)
- cmat.mul(scalar)
- cmat.mul(comp)
- cmat.mul(mat)
- cmat.mul(vec)
- cmat.mul(rvec)
- cmat.mul(mblock)
- cmat.mul(vblock)
- cmat.mul(rvblock)
- cmat.mul(cmat)
- cmat.mul(cvec)
- cmat.mul(crvec)
- cmat.mul(cmblock)
- cmat.mul(cvblock)
- cmat.mul(crvblock)
- cmat.mula(scalar)
- cmat.mula(comp)
- cmat.mula(mat)
- cmat.mula(vec)
- cmat.mula(rvec)
- cmat.mula(mblock)
- cmat.mula(vblock)
- cmat.mula(rvblock)
- cmat.mula(cmat)
- cmat.mula(cvec)
- cmat.mula(crvec)
- cmat.mula(cmblock)
- cmat.mula(cvblock)
- cmat.mula(crvblock)
- cmat.div(scalar)
- cmat.div(comp)
- cmat.diva(scalar)
- cmat.diva(comp)
- cmat.transpose()
- cmat.conjugate()
- cmat.adjoint()
- cmat.determinant()
- cmat.inverse()
- cmat.trace()
- cmat.diagonal([index = 0])
- cmat.norm()
- cmat.redux(func)
- cmat.sum()
- cmat.prod()
- cmat.mean()
- cmat.visit(func)
- cmat.equals(cmat)
- cmat.equals(cvec)
- cmat.equals(crvec)
- cmat.equals(cmblock)
- cmat.equals(cvblock)
- cmat.equals(crvblock)
- cmat.isApprox(cmat, [prec = 1e-12])
- cmat.isApprox(cvec, [prec = 1e-12])
- cmat.isApprox(crvec, [prec = 1e-12])
- cmat.isApprox(cmblock, [prec = 1e-12])
- cmat.isApprox(cvblock, [prec = 1e-12])
- cmat.isApprox(crvblock, [prec = 1e-12])
- cmat.isSquare()
- cmat.isZero([prec = 1e-12])
- cmat.isOnes([prec = 1e-12])
- cmat.isIdentity([prec = 1e-12])
- cmat.isDiagonal([prec = 1e-12])
- cmat.allFinite()
- cmat.hasNaN()
- cmat.partialPivLu()
- cmat.fullPivLu()
- cmat.toString([options])
- Complex Matrix Class Methods
- Vector inherits from Matrix
- Vector Class Methods
- Vector Instance Methods
- vec.set(row, scalar)
- vec.set(scalar_array)
- vec.get(row)
- vec.setLinSpaced(low, high)
- vec.setLinSpaced(size, low, high)
- vec.block(startRow, blockRows)
- vec.head(n)
- vec.tail(n)
- vec.dot(mat)
- vec.dot(vec)
- vec.dot(rvec)
- vec.dot(mblock)
- vec.dot(vblock)
- vec.dot(rvblock)
- vec.dot(cmat)
- vec.dot(cvec)
- vec.dot(crvec)
- vec.dot(cmblock)
- vec.dot(cvblock)
- vec.dot(crvblock)
- vec.asDiagonal()
- vec.normalize()
- vec.maxCoeff()
- vec.maxCoeff(obj)
- vec.maxCoeff(func)
- vec.minCoeff()
- vec.minCoeff(obj)
- vec.minCoeff(func)
- Complex Vector inherits from CMatrix
- Complex Vector Class Methods
- Complex Vector Instance Methods
- cvec.set(row, comp)
- cvec.set(comp_array)
- cvec.get(row)
- cvec.block(startRow, blockRows)
- cvec.head(n)
- cvec.tail(n)
- cvec.dot(mat)
- cvec.dot(vec)
- cvec.dot(rvec)
- cvec.dot(mblock)
- cvec.dot(vblock)
- cvec.dot(rvblock)
- cvec.dot(cmat)
- cvec.dot(cvec)
- cvec.dot(crvec)
- cvec.dot(cmblock)
- cvec.dot(cvblock)
- cvec.dot(crvblock)
- cvec.asDiagonal()
- cvec.normalize()
- Row Vector inherits from Matrix
- Row Vector Class Methods
- Row Vector Instance Methods
- rvec.set(col, scalar)
- rvec.set(scalar_array)
- rvec.get(col)
- rvec.setLinSpaced(low, high)
- rvec.setLinSpaced(size, low, high)
- rvec.block(startCol, blockCols)
- rvec.head(n)
- rvec.tail(n)
- rvec.dot(mat)
- rvec.dot(vec)
- rvec.dot(rvec)
- rvec.dot(mblock)
- rvec.dot(vblock)
- rvec.dot(rvblock)
- rvec.dot(cmat)
- rvec.dot(cvec)
- rvec.dot(crvec)
- rvec.dot(cmblock)
- rvec.dot(cvblock)
- rvec.dot(crvblock)
- rvec.asDiagonal()
- rvec.normalize()
- rvec.maxCoeff()
- rvec.maxCoeff(obj)
- rvec.maxCoeff(func)
- rvec.minCoeff()
- rvec.minCoeff(obj)
- rvec.minCoeff(func)
- Complex Row Vector inherits from CMatrix
- Complex Row Vector Class Methods
- CRowVector(mat)
- CRowVector(vec)
- CRowVector(rvec)
- CRowVector(mblock)
- CRowVector(vblock)
- CRowVector(rvblock)
- CRowVector(cmat)
- CRowVector(cvec)
- CRowVector(crvec)
- CRowVector(cmblock)
- CRowVector(cvblock)
- CRowVector(crvblock)
- CRowVector(cols)
- CRowVector(comp_array)
- CRowVector.Constant(cols, scalar)
- CRowVector.Constant(cols, comp)
- Complex Row Vector Instance Methods
- crvec.set(col, comp)
- crvec.set(comp_array)
- crvec.get(col)
- crvec.block(startCol, blockCols)
- crvec.head(n)
- crvec.tail(n)
- crvec.dot(mat)
- crvec.dot(vec)
- crvec.dot(rvec)
- crvec.dot(mblock)
- crvec.dot(vblock)
- crvec.dot(rvblock)
- crvec.dot(cmat)
- crvec.dot(cvec)
- crvec.dot(crvec)
- crvec.dot(cmblock)
- crvec.dot(cvblock)
- crvec.dot(crvblock)
- crvec.asDiagonal()
- crvec.normalize()
- Complex Row Vector Class Methods
- Matrix Block inherits from Matrix
- Complex Matrix Block inherits from CMatrix
- Vector Block inherits from Vector and MatrixBlock
- Complex Vector Block inherits from CVector and CMatrixBlock
- Row Vector Block inherits from RowVector and MatrixBlock
- Complex Row Vector Block inherits from CRowVector and CMatrixBlock
- Partial Pivoting LU
- Complex Partial Pivoting LU
- Full Pivoting LU
- Complex Full Pivoting LU
Complex
Complex Class Methods
Complex(real, [imag])
var C = require('eigenjs').Complex
, c = new C(3, -4);
console.log('c = %s', c);
c = (3,-4)
Complex.polar(scalar, scalar)
var C = require('eigenjs').Complex
, rho = 5
, theta = -0.9272952180016122
, c = C.polar(rho, theta);
console.log(c.conj().toString());
console.log(c.real * Math.cos(c.imag));
console.log(c.real * Math.sin(c.imag));
(5,0.927295)
3.0000000000000004
-3.9999999999999996
Complex.cos(scalar)
Complex.cos(comp)
var C = require('eigenjs').Complex
, c1 = new C(Math.PI/4, 0)
, c2 = C.cos(c1);
console.log(c2.toString());
(0.707107,-0)
Complex.cosh(scalar)
Complex.cosh(comp)
var C = require('eigenjs').Complex
, c1 = new C(0, 0)
, c2 = C.cosh(c1);
console.log(c2.toString());
(1,0)
Complex.exp(scalar)
Complex.exp(comp)
var C = require('eigenjs').Complex
, c1 = new C(1, 0)
, c2 = C.exp(c1);
console.log(c2.toString());
(2.71828,0)
Complex.log(scalar)
Complex.log(comp)
var C = require('eigenjs').Complex
, c1 = new C(Math.E, 0)
, c2 = C.log(c1);
console.log(c2.toString());
(1,0)
Complex.log10(scalar)
Complex.log10(comp)
var C = require('eigenjs').Complex
, c1 = new C(1000, 0)
, c2 = C.log10(c1);
console.log(c2.toString());
(3,0)
Complex.pow(scalar, scalar)
Complex.pow(scalar, comp)
Complex.pow(comp, scalar)
Complex.pow(comp, comp)
var C = require('eigenjs').Complex
, c = C.pow(2, 3)
console.log(c.toString());
(8,0)
Complex.sin(scalar)
Complex.sin(comp)
var C = require('eigenjs').Complex
, c1 = new C(Math.PI/4, 0)
, c2 = C.sin(c1);
console.log(c2.toString());
(0.707107,0)
Complex.sinh(scalar)
Complex.sinh(comp)
var C = require('eigenjs').Complex
, c1 = new C(0, 0)
, c2 = C.sinh(c1);
console.log(c2.toString());
(0,0)
Complex.sqrt(scalar)
Complex.sqrt(comp)
var C = require('eigenjs').Complex
, c1 = new C(9, 0)
, c2 = C.sqrt(c1);
console.log(c2.toString());
(3,0)
Complex.tan(scalar)
Complex.tan(comp)
var C = require('eigenjs').Complex
, c1 = new C(Math.PI/4, 0)
, c2 = C.tan(c1);
console.log(c2.toString());
(1,0)
Complex.tanh(scalar)
Complex.tanh(comp)
var C = require('eigenjs').Complex
, c1 = new C(Infinity, 0)
, c2 = C.tanh(c1);
console.log(c2.toString());
(1,0)
Complex.acos(scalar)
Complex.acos(comp)
var C = require('eigenjs').Complex
, c1 = new C(1, 0)
, c2 = C.acos(c1);
console.log(c2.toString());
(0,0)
Complex.acosh(scalar)
Complex.acosh(comp)
var C = require('eigenjs').Complex
, c1 = new C(1.54308, 0)
, c2 = C.acosh(c1);
console.log(c2.toString());
(0.999999,0)
Complex.asin(scalar)
Complex.asin(comp)
var C = require('eigenjs').Complex
, c1 = new C(1, 0)
, c2 = C.asin(c1);
console.log(c2.toString());
(1.5708,7.82511e-09)
Complex.asinh(scalar)
Complex.asinh(comp)
var C = require('eigenjs').Complex
, c1 = new C(1, 0)
, c2 = C.asinh(c1);
console.log(c2.toString());
(0.881374,0)
Complex.atan(scalar)
Complex.atan(comp)
var C = require('eigenjs').Complex
, c1 = new C(Infinity, 0)
, c2 = C.atan(c1);
console.log(c2.toString());
(1.5708,0)
Complex.atanh(scalar)
Complex.atanh(comp)
var C = require('eigenjs').Complex
, c1 = new C(1, 0)
, c2 = C.atanh(c1);
console.log(c2.toString());
(inf,0)
Complex Instance Methods
comp.abs()
var C = require('eigenjs').Complex
, c = new C(3, -4);
console.log(c.abs());
5
comp.arg()
var C = require('eigenjs').Complex
, c = new C(3, -4);
console.log(c.arg());
console.log('(%d,%d)', c.abs() * Math.cos(c.arg()), c.abs() * Math.sin(c.arg()));
-0.9272952180016122
(3.0000000000000004,-3.9999999999999996)
comp.norm()
var C = require('eigenjs').Complex
, c = new C(3, -4);
console.log(c.norm());
25
comp.conj()
var C = require('eigenjs').Complex
, c = new C(3, -4);
console.log(c.conj().toString());
(3,4)
comp.proj(scalar)
comp.proj(comp)
var C = require('eigenjs').Complex
, c1 = new C(0, -Infinity)
, c2 = C.proj(c1);
console.log(c2.toString());
(inf, -0)
comp.add(scalar)
comp.add(comp)
var C = require('eigenjs').Complex
, c1 = new C(3, 0)
, c2 = new C(0, 4)
, c3 = c1.add(c2);
console.log(c3.toString());
(3,4)
comp.adda(scalar)
comp.adda(comp)
var C = require('eigenjs').Complex
, c1 = new C(3, 0)
, c2 = new C(0, 4);
c1.adda(c2);
console.log(c1.toString());
(3,4)
comp.sub(scalar)
comp.sub(comp)
var C = require('eigenjs').Complex
, c1 = new C(3, 4)
, c2 = new C(2, -3)
, c3 = c1.sub(c2);
console.log(c3.toString());
(1,7)
comp.suba(scalar)
comp.suba(comp)
var C = require('eigenjs').Complex
, c1 = new C(5, 8)
, c2 = new C(-3, 4);
c1.suba(c2);
console.log(c1.toString());
(8,4)
comp.mul(scalar)
comp.mul(comp)
comp.mul(mat)
comp.mul(vec)
comp.mul(rvec)
comp.mul(mblock)
comp.mul(vblock)
comp.mul(rvblock)
comp.mul(cmat)
comp.mul(cvec)
comp.mul(crvec)
comp.mul(cmblock)
comp.mul(cvblock)
comp.mul(crvblock)
var C = require('eigenjs').Complex
, c1 = new C(1, 8)
, c2 = new C(6, 4)
, c3 = c1.mul(c2);
console.log(c3.toString());
(-26,52)
comp.mula(scalar)
comp.mula(comp)
var C = require('eigenjs').Complex
, c1 = new C(3, 1)
, c2 = new C(2, 4)
c1.mula(c2);
console.log(c1.toString());
(2,14)
comp.div(scalar)
comp.div(comp)
var C = require('eigenjs').Complex
, c1 = new C(4, 8)
, c2 = new C(2, 0)
, c3 = c1.div(c2);
console.log(c3.toString());
(2,4)
comp.diva(scalar)
comp.diva(comp)
var C = require('eigenjs').Complex
, c1 = new C(3, 9)
, c2 = new C(9, 0)
c1.diva(c2);
console.log(c2.toString());
(0.333333,1)
comp.equals(scalar)
comp.equals(comp)
var C = require('eigenjs').Complex
, c1 = new C(1, 0)
, c2 = c1.conj();
console.log(c1.equals(c2));
true
comp.isApprox(comp, [prec = 1e-12])
var C = require('eigenjs').Complex
, c1 = new C(1/3, 0)
, c2 = new C(0.3333, 0);
console.log(c1.isApprox(c2, 1e-3));
true
comp.toString()
var C = require('eigenjs').Complex
, c = new C(3, -4);
console.log(c.toString());
(3,-4)
Complex Properties
comp.real
comp.imag
var C = require('eigenjs').Complex
, c = new C(3, -4);
c.real = 6;
c.imag = 8;
console.log('(%d,%d)', c.real, c.imag);
(6,8)
Matrix
Matrix Class Methods
Matrix(mat)
Matrix(vec)
Matrix(rvec)
Matrix(mblock)
Matrix(vblock)
Matrix(rvblock)
var M = require('eigenjs').Matrix
, mat = new M.Random(2, 3)
, mat2 = new M(mat);
console.log('mat =\n%s\n', mat);
console.log('mat2 =\n%s', mat2);
mat =
0.381981 -0.373117 -0.866239
-0.0467884 -0.981309 -0.885573
mat2 =
0.381981 -0.373117 -0.866239
-0.0467884 -0.981309 -0.885573
Matrix(rows, cols)
var M = require('eigenjs').Matrix
, mat = new M(2, 3);
console.log('mat =\n%s', mat);
mat =
0 0 0
0 0 0
Matrix.Zero(n)
Matrix.Zero(rows, cols)
var M = require('eigenjs').Matrix
, mat = M.Zero(2, 3);
console.log('mat = \n%s', mat);
mat =
0 0 0
0 0 0
Matrix.Ones(n)
Matrix.Ones(rows, cols)
var M = require('eigenjs').Matrix
, mat = M.Ones(2, 3);
console.log('mat = \n%s', mat);
mat =
1 1 1
1 1 1
Matrix.Constant(rows, cols, scalar)
Matrix.Constant(rows, cols, comp)
var M = require('eigenjs').Matrix
, mat = M.Constant(4, 4, 0.6);
console.log('mat = \n%s', mat);
mat =
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6
Matrix.Random(n)
Matrix.Random(rows, cols)
var M = require('eigenjs').Matrix
, mat = M.Random(2, 3);
console.log('mat = \n%s', mat);
mat =
-0.421952 -0.671276 0.547419
0.260209 -0.13622 0.464891
Matrix.Identity(n)
Matrix.Identity(rows, cols)
var M = require('eigenjs').Matrix
, mat1 = M.Identity(2)
, mat2 = M.Identity(2, 3);
console.log('mat1 = \n%s', mat1);
console.log('mat2 = \n%s', mat2);
mat1 =
1 0
0 1
mat2 =
1 0 0
0 1 0
Matrix Instance Methods
mat.rows()
mat.cols()
var M = require('eigenjs').Matrix
, mat = new M(2, 3);
console.log(mat.rows());
console.log(mat.cols());
2
3
mat.set(row, col, scalar)
var M = require('eigenjs').Matrix
, mat = new M(2, 2);
mat.set(0, 0, 1)
.set(0, 1, 2)
.set(1, 0, 3)
.set(1, 1, 4);
console.log('mat = \n%s', mat);
mat =
1 2
3 4
mat.set(scalar_array)
var M = require('eigenjs').Matrix
, mat = new M(3, 3);
mat.set([
1, 2, 3,
4, 5, 6,
7, 8, 9
]);
console.log('mat = \n%s', mat);
mat =
1 2 3
4 5 6
7 8 9
mat.get(row, col)
var M = require('eigenjs').Matrix
, mat = new M(2, 2);
mat.set([
1, 2,
3, 4
]);
console.log(mat.get(0, 0) + ' ' + mat.get(0, 1));
console.log(mat.get(1, 0) + ' ' + mat.get(1, 1));
1 2
3 4
mat.assign(mat)
mat.assign(vec)
mat.assign(rvec)
mat.assign(mblock)
mat.assign(vblock)
mat.assign(rvblock)
var M = require('eigenjs').Matrix
, mat = M.Random(4, 4);
mat.assign(M.Zero(4, 4));
console.log('mat = \n%s', mat);
mat =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
mat.value()
Returns the unique coefficient of a 1x1 expression
var M = require('eigenjs').Matrix
, mat = M.Random(1, 1);
console.log('%d', mat.value());
-0.7131525574778916
mat.setZero()
var M = require('eigenjs').Matrix
, mat = new M.Random(3, 3);
console.log('mat =\n%s\n', mat);
console.log('mat =\n%s', mat.setZero());
mat =
0.244911 -0.752925 -0.562905
0.215088 -0.406688 -0.750836
0.983236 0.800109 0.695126
mat =
0 0 0
0 0 0
0 0 0
mat.setOnes()
var M = require('eigenjs').Matrix
, mat = new M.Zero(3, 3);
console.log('mat =\n%s\n', mat);
console.log('mat =\n%s', mat.setOnes());
mat =
0 0 0
0 0 0
0 0 0
mat =
1 1 1
1 1 1
1 1 1
mat.setConstant(scalar)
var M = require('eigenjs').Matrix
, mat = new M.Zero(3, 3);
console.log('mat =\n%s\n', mat);
console.log('mat =\n%s', mat.setConstant(0.6));
mat =
0 0 0
0 0 0
0 0 0
mat =
0.6 0.6 0.6
0.6 0.6 0.6
0.6 0.6 0.6
mat.setRandom()
var M = require('eigenjs').Matrix
, mat = new M.Zero(3, 3);
console.log('mat =\n%s\n', mat);
console.log('mat =\n%s', mat.setRandom());
mat =
0 0 0
0 0 0
0 0 0
mat =
-0.292434 -0.0673437 0.283946
-0.938224 0.154289 0.283845
-0.725773 -0.862362 0.583097
mat.setIdentity()
var M = require('eigenjs').Matrix
, mat = new M.Zero(3, 3);
console.log('mat =\n%s\n', mat);
console.log('mat =\n%s', mat.setIdentity());
mat =
0 0 0
0 0 0
0 0 0
mat =
1 0 0
0 1 0
0 0 1
mat.setDiagonal(index, vec)
mat.setDiagonal(index, rvec)
var M = require('eigenjs').Matrix
, mat = new M.Zero(3, 3)
, dia = mat.diagonal(1);
console.log('mat =\n%s\n', mat);
dia.setRandom();
console.log('mat =\n%s', mat.setDiagonal(1, dia));
mat =
0 0 0
0 0 0
0 0 0
mat =
0 -0.294006 0
0 0 0.634569
0 0 0
mat.block(startRow, startCol, blockRows, blockCols)
var M = require('eigenjs').Matrix
, mat = new M.Identity(4, 4)
, mblock = mat.block(1, 1, 2, 2);
mblock.assign(M.Random(2, 2));
console.log('mat =\n%s', mat);
mat =
1 0 0 0
0 -0.822352 0.533723 0
0 0.721993 0.287646 0
0 0 0 1
mat.row(n)
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, RV = Eigen.RowVector
, mat = new M.Zero(3, 3)
, mblock = mat.row(1);
mblock.assign(RV.Random(3));
console.log('mat =\n%s', mat);
mat =
0 0 0
-0.843392 -0.891355 0.991578
0 0 0
mat.col(n)
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, V = Eigen.Vector
, mat = new M.Zero(3, 3)
, mblock = mat.col(1);
mblock.assign(V.Random(3));
console.log('mat =\n%s', mat);
mat =
0 0.674939 0
0 -0.303923 0
0 -0.0302965 0
mat.topRows(n)
Returns a block consisting of the top rows of *this.
var M = require('eigenjs').Matrix
, mat = new M(4, 4).set([
7, 9, -5, 3,
-2, -6, 1, 0,
6, -3, 0, 9,
6, 6, 3, 9
]);
console.log('%s', mat.topRows(2));
7 9 -5 3
-2 -6 1 0
mat.bottomRows(n)
Returns a block consisting of the bottom rows of *this.
var M = require('eigenjs').Matrix
, mat = new M(4, 4).set([
7, 9, -5, 3,
-2, -6, 1, 0,
6, -3, 0, 9,
6, 6, 3, 9
]);
console.log('%s', mat.bottomRows(2));
6 -3 0 9
6 6 3 9
mat.middleRows(startRow, n)
Returns a block consisting of a range of rows of *this.
var M = require('eigenjs').Matrix
, mat = new M(4, 4).set([
7, 9, -5, 3,
-2, -6, 1, 0,
6, -3, 0, 9,
6, 6, 3, 9
]);
console.log('%s', mat.middleRows(1, 2));
-2 -6 1 0
6 -3 0 9
mat.leftCols(n)
Returns a block consisting of the left columns of *this.
var M = require('eigenjs').Matrix
, mat = new M(4, 4).set([
7, 9, -5, 3,
-2, -6, 1, 0,
6, -3, 0, 9,
6, 6, 3, 9
]);
console.log('%s', mat.leftCols(2));
7 9
-2 -6
6 -3
6 6
mat.rightCols(n)
Returns a block consisting of the right columns of *this.
var M = require('eigenjs').Matrix
, mat = new M(4, 4).set([
7, 9, -5, 3,
-2, -6, 1, 0,
6, -3, 0, 9,
6, 6, 3, 9
]);
console.log('%s', mat.rightCols(2));
-5 3
1 0
0 9
3 9
mat.middleCols(startCol, n)
Returns a block consisting of a range of columns of *this.
var M = require('eigenjs').Matrix
, mat = new M(4, 4).set([
7, 9, -5, 3,
-2, -6, 1, 0,
6, -3, 0, 9,
6, 6, 3, 9
]);
console.log('%s', mat.middleCols(1, 2));
9 -5
-6 1
-3 0
6 3
mat.topLeftCorner(cRows, cCols)
Returns a block consisting of a top-left corner of *this.
var M = require('eigenjs').Matrix
, mat = new M(4, 4).set([
7, 9, -5, 3,
-2, -6, 1, 0,
6, -3, 0, 9,
6, 6, 3, 9
]);
console.log('%s', mat.topLeftCorner(2, 2));
7 9
-2 -6
mat.topRightCorner(cRows, cCols)
Returns a block consisting of a top-right corner of *this.
var M = require('eigenjs').Matrix
, mat = new M(4, 4).set([
7, 9, -5, 3,
-2, -6, 1, 0,
6, -3, 0, 9,
6, 6, 3, 9
]);
console.log('%s', mat.topRightCorner(2, 2));
-5 3
1 0
mat.bottomLeftCorner(cRows, cCols)
Returns a block consisting of a bottom-left corner of *this.
var M = require('eigenjs').Matrix
, mat = new M(4, 4).set([
7, 9, -5, 3,
-2, -6, 1, 0,
6, -3, 0, 9,
6, 6, 3, 9
]);
console.log('%s', mat.bottomLeftCorner(2, 2));
6 -3
6 6
mat.bottomRightCorner(cRows, cCols)
Returns a block consisting of a bottom-right corner of *this.
var M = require('eigenjs').Matrix
, mat = new M(4, 4).set([
7, 9, -5, 3,
-2, -6, 1, 0,
6, -3, 0, 9,
6, 6, 3, 9
]);
console.log('%s', mat.bottomRightCorner(2, 2));
0 9
3 9
mat.replicate(rowFactor, colFactor)
var M = require('eigenjs').Matrix
, mat = new M(3, 1).set([
7,
-2,
6
]);
console.log('%s', mat.replicate(2, 5));
7 7 7 7 7
-2 -2 -2 -2 -2
6 6 6 6 6
7 7 7 7 7
-2 -2 -2 -2 -2
6 6 6 6 6
mat.add(mat)
mat.add(vec)
mat.add(rvec)
mat.add(mblock)
mat.add(vblock)
mat.add(rvblock)
mat.add(cmat)
mat.add(cvec)
mat.add(crvec)
mat.add(cmblock)
mat.add(cvblock)
mat.add(crvblock)
var M = require('eigenjs').Matrix
, mat1 = new M(2, 2)
, mat2 = new M(2, 2)
, mat3;
mat1.set([
1, 3,
2, 4
]);
mat2.set([
5, 6,
7, 8
]);
mat3 = mat1.add(mat2);
console.log('mat3 = \n%s', mat3);
mat3 =
6 9
9 12
mat.adda(mat)
mat.adda(vec)
mat.adda(rvec)
mat.adda(mblock)
mat.adda(vblock)
mat.adda(rvblock)
var M = require('eigenjs').Matrix
, mat1 = new M(2, 2)
, mat2 = new M(2, 2);
mat1.set([
1, 3,
2, 4
]);
mat2.set([
5, 6,
7, 8
]);
mat1.adda(mat2);
console.log('mat1 = \n%s', mat1);
mat1 =
6 9
9 12
mat.sub(mat)
mat.sub(vec)
mat.sub(rvec)
mat.sub(mblock)
mat.sub(vblock)
mat.sub(rvblock)
mat.sub(cmat)
mat.sub(cvet)
mat.sub(crvet)
mat.sub(cmblock)
mat.sub(cvblock)
mat.sub(crvblock)
var M = require('eigenjs').Matrix
, mat1 = new M(2, 2)
, mat2 = new M(2, 2)
, mat3;
mat1.set([
1, 3,
2, 4
]);
mat2.set([
5, 6,
7, 8
]);
mat3 = mat1.sub(mat2);
console.log('mat3 = \n%s', mat3);
mat3 =
-4 -3
-5 -4
mat.suba(mat)
mat.suba(vec)
mat.suba(rvec)
mat.suba(mblock)
mat.suba(vblock)
mat.suba(rvblock)
var M = require('eigenjs').Matrix
, mat1 = new M(2, 2)
, mat2 = new M(2, 2);
mat1.set([
1, 3,
2, 4
]);
mat2.set([
5, 6,
7, 8
]);
mat1.suba(mat2);
console.log('mat1 = \n%s', mat1);
mat1 =
-4 -3
-5 -4
mat.mul(scalar)
mat.mul(comp)
mat.mul(mat)
mat.mul(vec)
mat.mul(rvec)
mat.mul(mblock)
mat.mul(vblock)
mat.mul(rvblock)
mat.mul(cmat)
mat.mul(cvec)
mat.mul(crvec)
mat.mul(cvblock)
mat.mul(crvblock)
var M = require('eigenjs').Matrix
, mat1 = new M(2, 3)
, vec = new M(3, 1)
, mat2;
mat1.set([
1, 2, 3,
4, 5, 6
]);
vec.set([
1,
6,
8
]);
mat2 = mat1.mul(vec);
console.log('mat2 = \n%s', mat2);
mat2 =
37
82
mat.mula(scalar)
mat.mula(mat)
mat.mula(vec)
mat.mula(rvec)
mat.mula(mblock)
mat.mula(vblock)
mat.mula(rvblock)
var M = require('eigenjs').Matrix
, mat = new M(2, 3)
, vec = new M(3, 1);
mat.set([
1, 2, 3,
4, 5, 6
]);
vec.set([
1,
6,
8
]);
mat.mula(vec);
console.log('mat = \n%s', mat);
mat =
37
82
mat.div(scalar)
mat.div(comp)
var M = require('eigenjs').Matrix
, mat1 = new M(2, 2)
, mat2;
mat1.set([
1, 2,
3, 4
]);
mat2 = mat1.div(2);
console.log('mat2 = \n%s', mat2);
mat2 =
0.5 1
1.5 2
mat.diva(scalar)
var M = require('eigenjs').Matrix
, mat = new M(2, 2);
mat.set([
1, 2,
3, 4
]);
mat.diva(2);
console.log('mat = \n%s', mat);
mat =
0.5 1
1.5 2
mat.transpose()
var M = require('eigenjs').Matrix
, mat1 = new M.Random(3, 2)
, mat2 = mat1.transpose();
console.log('mat1 = \n%s', mat1);
console.log('mat2 = \n%s', mat2);
mat1 =
-0.112813 -0.325566
-0.0500345 0.213005
-0.930346 -0.022705
mat2 =
-0.112813 -0.0500345 -0.930346
-0.325566 0.213005 -0.022705
mat.conjugate()
var M = require('eigenjs').Matrix
, mat1 = new M.Random(2, 2)
, mat2 = mat1.conjugate();
console.log(mat1.equals(mat2));
true
mat.adjoint()
var M = require('eigenjs').Matrix
, mat1 = new M.Random(3, 2)
, mat2 = mat1.adjoint();
console.log('mat1 = \n%s', mat1);
console.log('mat2 = \n%s', mat2);
mat1 =
0.997487 0.0670765
0.770148 -0.645138
-0.12185 -0.835853
mat2 =
0.997487 0.770148 -0.12185
0.0670765 -0.645138 -0.835853
mat.determinant()
Returns the determinant of this matrix. This method uses class PartialPivLU.
var M = require('eigenjs').Matrix
, mat = new M.Random(2, 2);
console.log('mat = \n%s\n', mat);
console.log('det = %d', mat.determinant());
mat =
0.132371 -0.813862
0.758326 -0.58171
det = 0.540171350604003
mat.inverse()
Returns the matrix inverse of this matrix. This method uses class PartialPivLU.
var M = require('eigenjs').Matrix
, mat = new M(3, 3).set([
1, 2, 3,
0, 1, 4,
5, 6, 0
])
, inv = mat.inverse();
console.log('inv = \n%s', inv);
inv =
-24 18 5
20 -15 -4
-5 4 1
mat.trace()
var M = require('eigenjs').Matrix
, mat = new M(2, 3).set([
1, 2, 3,
4, 5, 6
])
, tr = mat.trace();
console.log('mat = \n%s\n', mat);
console.log('tr = ', tr);
mat =
1 2 3
4 5 6
tr = 6
mat.diagonal([index = 0])
var M = require('eigenjs').Matrix
, mat = new M(4, 4).set([
7, 9, -5, -3,
-2, -6, 1, 0,
6, -3, 0, 9,
6, 6, 3, 9
]);
console.log('%s', mat.diagonal(1).transpose());
console.log('%s', mat.diagonal(-2).transpose());
9 1 9
6 6
mat.norm()
Returns the Frobenius norm.
var M = require('eigenjs').Matrix
, mat = new M(3, 3).set([
1, 2, 3,
4, 5, 6,
7, 8, 9
]);
console.log('%d', mat.norm());
16.881943016134134
mat.redux(func)
- func
Function
The result of a full redux operation on the whoie matrix or vector usingfunc
.
var M = require('eigenjs').Matrix
, mat = new M(3, 3).set([
1, 2, 3,
4, 5, 6,
7, 8, 9
])
, func = function(a, b) { return a + b; };
console.log('%d', mat.redux(func));
45
mat.sum()
var M = require('eigenjs').Matrix
, mat = new M(3, 3).set([
1, 2, 3,
4, 5, 6,
7, 8, 9
]);
console.log('%d', mat.sum());
45
mat.prod()
var M = require('eigenjs').Matrix
, mat = new M(3, 3).set([
1, 2, 3,
4, 5, 6,
7, 8, 9
]);
console.log('%d', mat.prod());
362880
mat.mean()
var M = require('eigenjs').Matrix
, mat = new M(3, 3).set([
1, 2, 3,
4, 5, 6,
7, 8, 9
]);
console.log('%d', mat.mean());
5
mat.visit(func)
- func
Function
Applies thefunc
to the whole coefficients of the matrix or vector.
var M = require('eigenjs').Matrix
, mat = new M(3, 3).set([
1, 2, 3,
4, 5, 6,
7, 8, 9
]);
mat.visit(function(value, row, col) {
console.log('mat(%d, %d) = %d', row, col, value);
});
mat(0, 0) = 1
mat(1, 0) = 4
mat(2, 0) = 7
mat(0, 1) = 2
mat(1, 1) = 5
mat(2, 1) = 8
mat(0, 2) = 3
mat(1, 2) = 6
mat(2, 2) = 9
mat.maxCoeff()
var M = require('eigenjs').Matrix
, mat = new M.Random(3, 3);
console.log('mat = \n%s\n', mat);
console.log('max = %d', mat.maxCoeff());
mat =
0.175793 -0.547068 -0.959701
0.561311 -0.579446 0.297471
-0.0382309 -0.743676 -0.411312
max = 0.5613114636211243
mat.maxCoeff(obj)
- obj
Object
var M = require('eigenjs').Matrix
, mat = new M.Random(3, 3)
, obj = {};
console.log('mat = \n%s\n', mat);
console.log('max = %s', mat.maxCoeff(obj));
console.log('obj = %s', JSON.stringify(obj));
mat =
-0.68294 0.690895 -0.698356
-0.174138 -0.119934 0.733219
-0.743578 0.262349 -0.795382
max = 0.7332185766348702
obj = {"maxCoeff":0.7332185766348702,"rowId":1,"colId":2}
mat.maxCoeff(func)
- func
Function
var M = require('eigenjs').Matrix
, mat = new M.Random(3, 3)
, func = function(rowId, colId) {
console.log('rowId = %d, colId = %d', rowId, colId);
};
console.log('mat = \n%s\n', mat);
console.log('max = %d', mat.maxCoeff(func));
mat =
-0.552622 -0.355055 0.141004
0.0814275 0.58272 -0.13819
0.552011 -0.217758 -0.551142
rowId = 1, colId = 1
max = 0.5827204285109044
mat.minCoeff()
var M = require('eigenjs').Matrix
, mat = new M.Random(3, 3);
console.log('mat = \n%s\n', mat);
console.log('min = %d', mat.minCoeff());
mat =
-0.725041 0.511321 0.29833
0.233345 -0.22101 0.0355704
-0.167162 -0.514649 -0.168438
min = -0.7250411527813604
mat.minCoeff(obj)
- obj
Object
var M = require('eigenjs').Matrix
, mat = new M.Random(3, 3)
, obj = {};
console.log('mat = \n%s\n', mat);
console.log('min = %d', mat.minCoeff(obj));
console.log('obj = %s', JSON.stringify(obj));
mat =
0.74568 0.870563 -0.82341
0.636928 -0.455949 0.944912
0.855648 0.872564 -0.87055
min = -0.8705498761825962
obj = {"minCoeff":-0.8705498761825962,"rowId":2,"colId":2}
mat.minCoeff(func)
- func
Function
var M = require('eigenjs').Matrix
, mat = new M.Random(3, 3)
, func = function(rowId, colId) {
console.log('rowId = %d, colId = %d', rowId, colId);
};
console.log('mat = \n%s\n', mat);
console.log('min = %d', mat.minCoeff(func));
0.371743 0.261372 0.144462
-0.111958 0.884582 -0.02937
0.314765 -0.823458 0.378298
rowId = 2, colId = 1
min = -0.8234578174648144
mat.equals(mat)
mat.equals(vec)
mat.equals(rvec)
mat.equals(mblock)
mat.equals(vblock)
mat.equals(rvblock)
var M = require('eigenjs').Matrix
, mat1 = new M(2, 2)
, mat2 = new M(2, 2)
, mat3 = new M(2, 2);
mat1.set([
1, 2,
3, 4
]);
mat2.set([
1, 0,
0, 1
]);
mat3.set([
0, 2,
3, 3
]);
console.log(mat1.equals(mat2.add(mat3)));
true
mat.isApprox(mat, [prec = 1e-12])
mat.isApprox(vec, [prec = 1e-12])
mat.isApprox(rvec, [prec = 1e-12])
mat.isApprox(mblock, [prec = 1e-12])
mat.isApprox(vblock, [prec = 1e-12])
mat.isApprox(rvblock, [prec = 1e-12])
var M = require('eigenjs').Matrix
, mat1 = new M(2, 2)
, mat2 = new M(2, 2);
mat1.set([
1, 3,
5, 7
]).diva(11);
mat2.set([
0.091, 0.273,
0.455, 0.636
]);
console.log(mat1.isApprox(mat2, 1e-3));
true
mat.isSquare()
var M = require('eigenjs').Matrix
, mat1 = new M(4, 4)
, mat2 = new M(3, 2);
console.log(mat1.isSquare());
console.log(mat2.isSquare());
true
false
mat.isZero([prec = 1e-12])
var M = require('eigenjs').Matrix
, mat = new M(2, 3).set([
0, 0, 0.0001,
0, 0, 0
]);
console.log(mat.isZero());
console.log(mat.isZero(1e-3));
false
true
mat.isOnes([prec = 1e-12])
var M = require('eigenjs').Matrix
, mat = new M(2, 3).set([
1, 1, 1.0001,
1, 0.9997, 1
]);
console.log(mat.isOnes());
console.log(mat.isOnes(1e-3));
false
true
mat.isIdentity([prec = 1e-12])
var M = require('eigenjs').Matrix
, mat = new M(3, 3).set([
1, 0, 0.0001,
0, 0.9997, 0,
0, 0, 1
]);
console.log(mat.isIdentity());
console.log(mat.isIdentity(1e-3));
false
true
mat.isDiagonal([prec = 1e-12])
var M = require('eigenjs').Matrix
, mat = new M(3, 3).set([
1e+04, 0, 1,
0, 1e+04, 0,
0, 0, 1e+04
]);
console.log(mat.isDiagonal());
console.log(mat.isDiagonal(1e-3));
false
true
mat.all()
Returns true if all coefficients are true.
var M = require('eigenjs').Matrix
, mat = new M.Constant(3, 3, 1);
console.log('mat = \n%s\n%s\n', mat, mat.all());
mat.set(0, 0, 0);
console.log('mat = \n%s\n%s', mat, mat.all());
mat =
1 1 1
1 1 1
1 1 1
true
mat =
0 1 1
1 1 1
1 1 1
false
mat.any()
Returns true if at least one coefficient is true.
var M = require('eigenjs').Matrix
, mat = new M.Zero(3, 3);
console.log('mat = \n%s\n%s\n', mat, mat.any());
mat.set(0, 0, 1);
console.log('mat = \n%s\n%s', mat, mat.any());
mat =
0 0 0
0 0 0
0 0 0
false
mat =
1 0 0
0 0 0
0 0 0
true
mat.count()
Returns the number of coefficients which evaluate to true.
var M = require('eigenjs').Matrix
, mat = new M.Zero(3, 3);
mat.block(0, 1, 3, 2).setOnes();
console.log('mat = \n%s\n', mat);
console.log('%d', mat.count());
mat =
0 1 1
0 1 1
0 1 1
6
mat.allFinite()
Returns true if *this contains only finite numbers, i.e., no NaN and no +/-INF values.
var M = require('eigenjs').Matrix
, mat = new M.Random(3, 3);
console.log('mat = \n%s\n%s\n', mat, mat.allFinite());
mat.set(0, 0, Infinity);
console.log('mat = \n%s\n%s', mat, mat.allFinite());
mat =
0.202332 0.271506 -0.887678
0.592388 -0.806422 0.799406
0.26443 0.461303 -0.389755
true
mat =
inf 0.271506 -0.887678
0.592388 -0.806422 0.799406
0.26443 0.461303 -0.389755
false
mat.hasNaN()
Returns true if *this contains at least one Not A Number (NaN).
var M = require('eigenjs').Matrix
, mat = new M.Zero(3, 3);
console.log('mat = \n%s\n%s\n', mat, mat.hasNaN());
mat.set(1, 1, NaN);
console.log('mat = \n%s\n%s', mat, mat.hasNaN());
mat =
0 0 0
0 0 0
0 0 0
false
mat =
0 0 0
0 nan 0
0 0 0
true
mat.partialPivLu()
Returns the partial-pivoting LU decomposition of *this.
var M = require('eigenjs').Matrix
, mat = new M(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, pplu = mat.partialPivLu();
console.log('P = \n%s\n', pplu.permutationP());
console.log('L = \n%s\n', pplu.matrixL());
console.log('U = \n%s', pplu.matrixU());
P =
0 0 1
0 1 0
1 0 0
L =
1 0 0
0.8 1 0
0.2 -1 1
U =
5 6 3
0 -2.8 3.6
0 0 8
mat.fullPivLu()
Returns the full-pivoting LU decomposition of *this.
var M = require('eigenjs').Matrix
, mat = new M(2, 4).set([
1, 1, 1, 3,
1, 2, -1, 4
])
, fplu = mat.fullPivLu();
console.log('P = \n%s\n', fplu.permutationP());
console.log('L = \n%s\n', fplu.matrixL());
console.log('U = \n%s\n', fplu.matrixU());
console.log('Q = \n%s', fplu.permutationQ());
P =
0 1
1 0
L =
1 0
0.75 1
U =
4 -1 2 1
0 1.75 -0.5 0.25
Q =
0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0
mat.toString([options])
- options
Object
- precision
Number
Default=6
. The number of digits for floating point values. - fullPrecision
Booleam
Default=false
. If set to true, then the number of digits will be computed to match the full precision of each floating-point type. - dontAlignCols
Booleam
Default=false
. If set to true, it allows to disable the alignment of columnt, resulting in faster code. - coeffSeparator
String
Default=' '
. The string printed between two coefficients of the same row. - rowSeparator
String
Default=''
. The string printed between two rows. - rowPrefix
String
Default=''
. The string printed at the beginning of each row. - rowSuffix
String
Default=''
. The string printed at the end of each row. - matPrefix
String
Default=''
. The string printed at the beginning of the matrix. - matSuffix
String
Default=''
. The string printed at the end of the matrix.
- precision
var M = require('eigenjs').Matrix
, mat = new M.Random(3, 3)
, cleanfmt = {
precision: 4
, coeffSeparator: ", "
, rowSeparator: "\n"
, rowPrefix: "["
, rowSuffix: "]"
};
console.log('mat =\n%s\n', mat.toString());
console.log('mat =\n' + mat.toString(cleanfmt));
mat =
0.611558 0.725525 -0.550208
0.457785 -0.0968169 0.657662
0.000162166 0.797849 -0.68232
mat =
[ 0.6116, 0.7255, -0.5502]
[ 0.4578, -0.09682, 0.6577]
[0.0001622, 0.7978, -0.6823]
Complex Matrix
Complex Matrix Class Methods
CMatrix(mat)
CMatrix(vec)
CMatrix(rvec)
CMatrix(mblock)
CMatrix(vblock)
CMatrix(rvblock)
CMatrix(cmat)
CMatrix(cvec)
CMatrix(crvec)
CMatrix(cmblock)
CMatrix(cvblock)
CMatrix(crvblock)
var CM = require('eigenjs').CMatrix
, cmat = new CM.Random(2, 3)
, cmat2 = new CM(cmat);
console.log('cmat =\n%s\n', cmat);
console.log('cmat2 =\n%s', cmat2);
cmat =
(-0.947988,-0.839555) (-0.502409,0.00732418) (0.402069,-0.422384)
(-0.40669,0.758583) (-0.902474,0.124615) (0.992439,-0.0813283)
cmat2 =
(-0.947988,-0.839555) (-0.502409,0.00732418) (0.402069,-0.422384)
(-0.40669,0.758583) (-0.902474,0.124615) (0.992439,-0.0813283)
CMatrix(rows, cols)
var CM = require('eigenjs').CMatrix
, cmat = new CM(2, 3);
console.log('cmat =\n%s', cmat);
cmat =
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
CMatrix.Zero(n)
CMatrix.Zero(rows, cols)
var CM = require('eigenjs').CMatrix
, cmat = CM.Zero(2, 3);
console.log('cmat = \n%s', cmat);
cmat =
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
CMatrix.Ones(n)
CMatrix.Ones(rows, cols)
var CM = require('eigenjs').CMatrix
, cmat = CM.Ones(2, 3);
console.log('cmat = \n%s', cmat);
cmat =
(1,0) (1,0) (1,0)
(1,0) (1,0) (1,0)
CMatrix.Constant(rows, cols, scalar)
CMatrix.Constant(rows, cols, comp)
var CM = require('eigenjs').CMatrix
, cmat = CM.Constant(4, 4, 0.6);
console.log('cmat = \n%s', cmat);
cmat =
(0.6,0) (0.6,0) (0.6,0) (0.6,0)
(0.6,0) (0.6,0) (0.6,0) (0.6,0)
(0.6,0) (0.6,0) (0.6,0) (0.6,0)
(0.6,0) (0.6,0) (0.6,0) (0.6,0)
CMatrix.Random(n)
CMatrix.Random(rows, cols)
var CM = require('eigenjs').CMatrix
, cmat = CM.Random(2, 3);
console.log('cmat = \n%s', cmat);
cmat =
(0.827048,0.18844) (-0.130621,0.648239) (-0.946608,0.364096)
(-0.895631,-0.864291) (0.952898,-0.648834) (-0.646252,0.440248)
CMatrix.Identity(n)
CMatrix.Identity(rows, cols)
var CM = require('eigenjs').CMatrix
, cmat1 = CM.Identity(2)
, cmat2 = CM.Identity(2, 3);
console.log('cmat1 = \n%s', cmat1);
console.log('cmat2 = \n%s', cmat2);
cmat1 =
(1,0) (0,0)
(0,0) (1,0)
cmat2 =
(1,0) (0,0) (0,0)
(0,0) (1,0) (0,0)
Complex Matrix Instance Methods
cmat.rows()
cmat.cols()
var CM = require('eigenjs').CMatrix
, cmat = new CM(2, 3);
console.log(cmat.rows());
console.log(cmat.cols());
2
3
cmat.set(row, col, comp)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 2);
cmat.set(0, 0, C(1, 1))
.set(0, 1, C(2, 2))
.set(1, 0, C(3, 3))
.set(1, 1, C(4, 4));
console.log('cmat = \n%s', cmat);
cmat =
(1,1) (2,2)
(3,3) (4,4)
cmat.set(comp_array)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(3, 3);
cmat.set([
C(1,1), C(2,2), C(3,3),
C(4,4), C(5,5), C(6,6),
C(7,7), C(8,8), C(9,9)
]);
console.log('cmat = \n%s', cmat);
cmat =
(1,1) (2,2) (3,3)
(4,4) (5,5) (6,6)
(7,7) (8,8) (9,9)
cmat.get(row, col)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 2);
cmat.set([
C(1,1), C(2,2),
C(3,3), C(4,4)
]);
console.log(cmat.get(0, 0) + ' ' + cmat.get(0, 1));
console.log(cmat.get(1, 0) + ' ' + cmat.get(1, 1));
(1,1) (2,2)
(3,3) (4,4)
cmat.assign(mat)
cmat.assign(vec)
cmat.assign(rvec)
cmat.assign(mblock)
cmat.assign(vblock)
cmat.assign(rvblock)
cmat.assign(cmat)
cmat.assign(cvec)
cmat.assign(crvec)
cmat.assign(cmblock)
cmat.assign(cvblock)
cmat.assign(crvblock)
var CM = require('eigenjs').CMatrix
, cmat = CM.Random(4, 4);
cmat.assign(CM.Zero(4, 4));
console.log('cmat = \n%s', cmat);
cmat =
(0,0) (0,0) (0,0) (0,0)
(0,0) (0,0) (0,0) (0,0)
(0,0) (0,0) (0,0) (0,0)
(0,0) (0,0) (0,0) (0,0)
cmat.value()
Returns the unique coefficient of a 1x1 expression
var CM = require('eigenjs').CMatrix
, cmat = CM.Random(1, 1);
console.log('%s', cmat.value());
(-0.402467,-0.259974)
cmat.setZero()
var CM = require('eigenjs').CMatrix
, cmat = new CM.Random(3, 3);
console.log('cmat =\n%s\n', cmat);
console.log('cmat =\n%s', cmat.setZero());
cmat =
(0.828056,-0.856655) (0.192893,-0.0390696) (-0.477729,0.812314)
(0.200923,0.904817) (-0.643549,-0.129635) (0.566937,0.514797)
(-0.740525,0.00155845) (-0.780958,0.437884) (0.194337,0.223802)
cmat =
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
cmat.setOnes()
var CM = require('eigenjs').CMatrix
, cmat = new CM.Zero(3, 3);
console.log('cmat =\n%s\n', cmat);
console.log('cmat =\n%s', cmat.setOnes());
cmat =
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
cmat =
(1,0) (1,0) (1,0)
(1,0) (1,0) (1,0)
(1,0) (1,0) (1,0)
cmat.setConstant(scalar)
cmat.setConstant(comp)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM.Zero(3, 3);
console.log('cmat =\n%s\n', cmat);
console.log('cmat =\n%s', cmat.setConstant(C(6, 8)));
cmat =
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
cmat =
(6,8) (6,8) (6,8)
(6,8) (6,8) (6,8)
(6,8) (6,8) (6,8)
cmat.setRandom()
var CM = require('eigenjs').CMatrix
, cmat = new CM.Zero(3, 3);
console.log('cmat =\n%s\n', cmat);
console.log('cmat =\n%s', cmat.setRandom());
cmat =
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
cmat =
(0.298345,0.285858) (-0.693147,0.286686) (-0.91605,-0.0576106)
(0.410026,-0.685715) (0.33597,0.656071) (-0.261633,0.736407)
(-0.808358,-0.0710831) (0.588954,0.544957) (0.800236,-0.434336)
mat.setIdentity()
var CM = require('eigenjs').CMatrix
, cmat = new CM.Zero(3, 3);
console.log('cmat =\n%s\n', cmat);
console.log('cmat =\n%s', cmat.setIdentity());
cmat =
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
cmat =
(1,0) (0,0) (0,0)
(0,0) (1,0) (0,0)
(0,0) (0,0) (1,0)
mat.setDiagonal(index, vec)
mat.setDiagonal(index, rvec)
mat.setDiagonal(index, cvec)
mat.setDiagonal(index, crvec)
var CM = require('eigenjs').CMatrix
, cmat = new M.Random(3, 3)
, dia = cmat.diagonal(1);
console.log('cmat = \n%s\n', cmat);
dia.setZero();
console.log('cmat =\n%s', cmat.setDiagonal(1, dia));
cmat =
0.103146 0.540894 0.490517
-0.433484 0.804028 0.127162
0.438421 -0.707295 -0.785343
cmat =
0.103146 0 0.490517
-0.433484 0.804028 0
0.438421 -0.707295 -0.785343
cmat.block(startRow, startCol, blockRows, blockCols)
var CM = require('eigenjs').CMatrix
, cmat = new CM.Identity(4, 4)
, cmblock = cmat.block(1, 1, 2, 2);
cmblock.assign(CM.Random(2, 2));
console.log('cmat =\n%s', cmat);
cmat =
(1,0) (0,0) (0,0) (0,0)
(0,0) (0.490586,-0.722033) (-0.380859,0.895456) (0,0)
(0,0) (0.794101,0.457882) (-0.068657,0.081439) (0,0)
(0,0) (0,0) (0,0) (1,0)
cmat.row(n)
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CRV = Eigen.CRowVector
, cmat = new CM.Zero(3, 3)
, cmblock = cmat.row(1);
cmblock.assign(CRV.Random(3));
console.log('cmat =\n%s', cmat);
cmat =
(0,0) (0,0) (0,0)
(0.500827,-0.595426) (0.677855,0.716979) (0.271854,-0.943846)
(0,0) (0,0) (0,0)
cmat.col(n)
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CV = Eigen.CVector
, cmat = new CM.Zero(3, 3)
, cmblock = cmat.col(1);
cmblock.assign(CV.Random(3));
console.log('cmat =\n%s', cmat);
cmat =
(0,0) (-0.97615,-0.147) (0,0)
(0,0) (-0.630134,-0.661642) (0,0)
(0,0) (-0.211411,0.819724) (0,0)
cmat.topRows(n)
Returns a block consisting of the top rows of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(4, 2).set([
C( 1, 2), C( 3, 4),
C( 5, 6), C( 7, 8),
C( 9, 10), C(11, 12),
C(13, 14), C(15, 16)
]);
console.log('%s', cmat.topRows(2));
(1,2) (3,4)
(5,6) (7,8)
cmat.bottomRows(n)
Returns a block consisting of the bottom rows of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(4, 2).set([
C( 1, 2), C( 3, 4),
C( 5, 6), C( 7, 8),
C( 9, 10), C(11, 12),
C(13, 14), C(15, 16)
]);
console.log('%s', cmat.bottomRows(2));
(9,10) (11,12)
(13,14) (15,16)
cmat.middleRows(startRow, n)
Returns a block consisting of a range of rows of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(4, 2).set([
C( 1, 2), C( 3, 4),
C( 5, 6), C( 7, 8),
C( 9, 10), C(11, 12),
C(13, 14), C(15, 16)
]);
console.log('%s', cmat.middleRows(1, 2));
(5,6) (7,8)
(9,10) (11,12)
cmat.leftCols(n)
Returns a block consisting of the left columns of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(4, 2).set([
C( 1, 2), C( 3, 4),
C( 5, 6), C( 7, 8),
C( 9, 10), C(11, 12),
C(13, 14), C(15, 16)
]);
console.log('%s', cmat.leftCols(1));
(1,2)
(5,6)
(9,10)
(13,14)
cmat.rightCols(n)
Returns a block consisting of the right columns of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(4, 2).set([
C( 1, 2), C( 3, 4),
C( 5, 6), C( 7, 8),
C( 9, 10), C(11, 12),
C(13, 14), C(15, 16)
]);
console.log('%s', cmat.rightCols(1));
(3,4)
(7,8)
(11,12)
(15,16)
cmat.middleCols(startCol, n)
Returns a block consisting of a range of columns of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(4, 2).set([
C( 1, 2), C( 3, 4),
C( 5, 6), C( 7, 8),
C( 9, 10), C(11, 12),
C(13, 14), C(15, 16)
]);
console.log('%s', cmat.middleCols(1, 1));
(3,4)
(7,8)
(11,12)
(15,16)
cmat.topLeftCorner(cRows, cCols)
Returns a block consisting of a top-left corner of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(4, 2).set([
C( 1, 2), C( 3, 4),
C( 5, 6), C( 7, 8),
C( 9, 10), C(11, 12),
C(13, 14), C(15, 16)
]);
console.log('%s', cmat.topLeftCorner(2, 1));
(1,2)
(5,6)
cmat.topRightCorner(cRows, cCols)
Returns a block consisting of a top-right corner of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(4, 2).set([
C( 1, 2), C( 3, 4),
C( 5, 6), C( 7, 8),
C( 9, 10), C(11, 12),
C(13, 14), C(15, 16)
]);
console.log('%s', cmat.topRightCorner(2, 1));
(3,4)
(7,8)
cmat.bottomLeftCorner(cRows, cCols)
Returns a block consisting of a bottom-left corner of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(4, 2).set([
C( 1, 2), C( 3, 4),
C( 5, 6), C( 7, 8),
C( 9, 10), C(11, 12),
C(13, 14), C(15, 16)
]);
console.log('%s', cmat.bottomLeftCorner(2, 1));
(9,10)
(13,14)
cmat.bottomRightCorner(cRows, cCols)
Returns a block consisting of a bottom-right corner of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(4, 2).set([
C( 1, 2), C( 3, 4),
C( 5, 6), C( 7, 8),
C( 9, 10), C(11, 12),
C(13, 14), C(15, 16)
]);
console.log('%s', cmat.bottomRightCorner(2, 1));
(11,12)
(15,16)
cmat.replicate(rowFactor, colFactor)
var CM = require('eigenjs').CMatrix
, cmat = new CM(3, 1).set([
7,
-2,
6
]);
console.log('%s', cmat.replicate(2, 5));
(7,0) (7,0) (7,0) (7,0) (7,0)
(-2,0) (-2,0) (-2,0) (-2,0) (-2,0)
(6,0) (6,0) (6,0) (6,0) (6,0)
(7,0) (7,0) (7,0) (7,0) (7,0)
(-2,0) (-2,0) (-2,0) (-2,0) (-2,0)
(6,0) (6,0) (6,0) (6,0) (6,0)
cmat.add(mat)
cmat.add(vec)
cmat.add(rvec)
cmat.add(mblock))
cmat.add(vblock)
cmat.add(rvblock)
cmat.add(cmat)
cmat.add(cvec)
cmat.add(crvec)
cmat.add(cmblock)
cmat.add(cvblock)
cmat.add(crvblock)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat1 = new CM(2, 2)
, cmat2 = new CM(2, 2)
, cmat3;
cmat1.set([
C(1,1), C(2,2),
C(3,3), C(4,4)
]);
cmat2.set([
5 , 6 ,
C(7,7), C(8,8)
]);
cmat3 = cmat1.add(cmat2);
console.log('cmat3 = \n%s', cmat3);
cmat3 =
(6,1) (8,2)
(10,10) (12,12)
cmat.adda(mat)
cmat.adda(vec)
cmat.adda(rvec)
cmat.adda(mblock)
cmat.adda(vblock)
cmat.adda(rvblock)
cmat.adda(cmat)
cmat.adda(cvec)
cmat.adda(crvec)
cmat.adda(cmblock)
cmat.adda(cvblock)
cmat.adda(crvblock)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat1 = new CM(2, 2)
, cmat2 = new CM(2, 2);
cmat1.set([
C(1,1), C(2,2),
C(3,3), C(4,4)
]);
cmat2.set([
5, 6,
7, 8
]);
cmat1.adda(cmat2);
console.log('cmat1 = \n%s', cmat1);
cmat1 =
(6,1) (8,2)
(10,3) (12,4)
cmat.sub(mat)
cmat.sub(vec)
cmat.sub(rvec)
cmat.sub(mblock)
cmat.sub(vblock)
cmat.sub(rvblock)
cmat.sub(cmat)
cmat.sub(cvec)
cmat.sub(crvec)
cmat.sub(cmblock)
cmat.sub(cvblock)
cmat.sub(crvblock)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat1 = new CM(2, 2)
, cmat2 = new CM(2, 2)
, cmat3;
cmat1.set([
C(1,1), C(2,2),
C(3,3), C(4,4)
]);
cmat2.set([
5, 6,
7, 8
]);
cmat3 = cmat1.sub(cmat2);
console.log('cmat3 = \n%s', cmat3);
cmat3 =
(-4,1) (-4,2)
(-4,3) (-4,4)
cmat.suba(mat)
cmat.suba(vec)
cmat.suba(rvec)
cmat.suba(mblock)
cmat.suba(vblock)
cmat.suba(rvblock)
cmat.suba(cmat)
cmat.suba(cvec)
cmat.suba(crvec)
cmat.suba(cmblock)
cmat.suba(vblock)
cmat.suba(rvblock)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat1 = new CM(2, 2)
, cmat2 = new CM(2, 2);
cmat1.set([
C(1,1), C(2,2),
C(3,3), C(4,4)
]);
cmat2.set([
5, 6,
7, 8
]);
cmat1.suba(cmat2);
console.log('cmat1 = \n%s', cmat1);
mat1 =
(-4,1) (-4,2)
(-4,3) (-4,4)
cmat.mul(scalar)
cmat.mul(comp)
cmat.mul(mat)
cmat.mul(vec)
cmat.mul(rvec)
cmat.mul(mblock)
cmat.mul(vblock)
cmat.mul(rvblock)
cmat.mul(cmat)
cmat.mul(cvec)
cmat.mul(crvec)
cmat.mul(cmblock)
cmat.mul(cvblock)
cmat.mul(crvblock)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, M = Eigen.Matrix
, CM = Eigen.CMatrix
, cmat1 = new CM(2, 3)
, vec = new M(3, 1)
, cmat2;
cmat1.set([
C(1,1), C(2,2), C(3,3),
C(4,4), C(5,5), C(6,6)
]);
vec.set([
1,
2,
3
]);
cmat2 = cmat1.mul(vec);
console.log('cmat2 = \n%s', cmat2);
mat2 =
(14,14)
(32,32)
cmat.mula(scalar)
cmat.mula(comp)
cmat.mula(mat)
cmat.mula(vec)
cmat.mula(rvec)
cmat.mula(mblock)
cmat.mula(vblock)
cmat.mula(rvblock)
cmat.mula(cmat)
cmat.mula(cvec)
cmat.mula(crvec)
cmat.mula(cmblock)
cmat.mula(cvblock)
cmat.mula(crvblock)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 3)
, c = new C(1, -1);
cmat.set([
C(1,1), C(2,2), C(3,3),
C(4,4), C(5,5), C(6,6)
]);
cmat.mula(c);
console.log('cmat = \n%s', cmat);
cmat =
(2,0) (4,0) (6,0)
(8,0) (10,0) (12,0)
cmat.div(scalar)
cmat.div(comp)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat1 = new CM(2, 2)
, cmat2 = new CM(2, 2);
cmat1.set([
C(1,1), C(2,2),
C(3,3), C(4,4)
]);
cmat2 = cmat1.div(C(2,0));
console.log('cmat2 = \n%s', cmat2);
cmat2 =
(0.5,0.5) (1,1)
(1.5,1.5) (2,2)
cmat.diva(scalar)
cmat.diva(comp)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 2)
cmat.set([
C(1,1), C(2,2),
C(3,3), C(4,4)
]);
cmat.diva(2);
console.log('cmat = \n%s', cmat);
cmat =
(0.5,0.5) (1,1)
(1.5,1.5) (2,2)
cmat.transpose()
var CM = require('eigenjs').CMatrix
, cmat1 = new CM.Random(3, 2)
, cmat2 = cmat1.transpose();
console.log('cmat1 = \n%s', cmat1);
console.log('cmat2 = \n%s', cmat2);
cmat1 =
(-0.0175928,0.317664) (0.0405036,0.744415)
(0.980286,-0.33036) (-0.617894,-0.94324)
(-0.360953,-0.543819) (0.958967,-0.649626)
cmat2 =
(-0.0175928,0.317664) (0.980286,-0.33036) (-0.360953,-0.543819)
(0.0405036,0.744415) (-0.617894,-0.94324) (0.958967,-0.649626)
cmat.conjugate()
var CM = require('eigenjs').CMatrix
, cmat1 = new CM.Random(2, 2)
, cmat2 = cmat1.conjugate();
console.log('cmat1 = \n%s', cmat1);
console.log('cmat2 = \n%s', cmat2);
cmat1 =
(-0.241556,0.172337) (0.87717,0.591998)
(0.472778,-0.0217244) (-0.291438,-0.198262)
cmat2 =
(-0.241556,-0.172337) (0.87717,-0.591998)
(0.472778,0.0217244) (-0.291438,0.198262)
cmat.adjoint()
var CM = require('eigenjs').CMatrix
, cmat1 = new CM.Random(3, 2)
, cmat2 = cmat1.adjoint();
console.log('cmat1 = \n%s', cmat1);
console.log('cmat2 = \n%s', cmat2);
cmat1 =
(-0.431879,-0.597577) (0.956798,0.90183)
(0.525477,-0.313942) (-0.943631,0.390357)
(-0.415382,0.66716) (0.737088,0.238193)
cmat2 =
(-0.431879,0.597577) (0.525477,0.313942) (-0.415382,-0.66716)
(0.956798,-0.90183) (-0.943631,-0.390357) (0.737088,-0.238193)
cmat.determinant()
Returns the determinant of this matrix. This method uses class CPartialPivLU.
var CM = require('eigenjs').CMatrix
, cmat = new CM.Random(2, 2);
console.log('cmat = \n%s\n', cmat);
console.log('det = %s', mat.determinant());
cmat =
(0.528893,-0.900902) (-0.307532,-0.690669)
(0.541616,0.947563) (-0.072443,0.450036)
det = (-0.120764,0.968768)
cmat.inverse()
Returns the matrix inverse of this matrix. This method uses class CPartialPivLU.
var CM = require('eigenjs').CMatrix
, cmat = new CM(3, 3).set([
1, 2, 3,
0, 1, 4,
5, 6, 0
])
, inv = cmat.inverse();
console.log('inv = \n%s', inv);
inv =
(-24,0) (18,0) (5,0)
(20,0) (-15,0) (-4,0)
(-5,-0) (4,0) (1,0)
cmat.trace()
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 3).set([
1, 2 , 3,
4, C(5, 6), 7
])
, tr = cmat.trace();
console.log('cmat = \n%s\n', cmat);
console.log('tr = %s', tr);
cmat =
(1,0) (2,0) (3,0)
(4,0) (5,6) (7,0)
tr = (6,6)
cmat.diagonal([index = 0])
var CM = require('eigenjs').CMatrix
, cmat = CM.Random(2, 3);
console.log('cmat = \n%s\n', cmat);
console.log('%s', cmat.diagonal());
cmat =
(0.345978,0.85694) (0.99589,-0.0742672) (-0.763035,-0.329107)
(0.592024,0.15202) (-0.20903,0.834369) (0.692856,0.838519)
(0.345978,0.85694)
(-0.20903,0.834369)
cmat.norm()
Returns the Frobenius norm.
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 2).set([
C(1, 2), C(3, 4),
C(5, 6), C(7, 9)
]);
console.log('%d', cmat.norm());
14.866068747318506
cmat.redux(func)
- func
Function
The result of a full redux operation on the whoie matrix or vector usingfunc
.
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 2).set([
C(1, 2), C(3, 4),
C(5, 6), C(7, 8)
])
, func = function(a, b) { return a.add(b); };
console.log('%s', cmat.redux(func));
(16,20)
cmat.sum()
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 2).set([
C(1, 2), C(3, 4),
C(5, 6), C(7, 8)
]);
console.log('%s', cmat.sum());
(16,20)
cmat.prod()
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 2).set([
C(1, 2), C(3, 4),
C(5, 6), C(7, 8)
]);
console.log('%s', cmat.prod());
(-755,-540)
cmat.mean()
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 2).set([
C(1, 2), C(3, 4),
C(5, 6), C(7, 8)
]);
console.log('%s', cmat.mean());
(4,5)
cmat.visit(func)
- func
Function
Applies thefunc
to the whole coefficients of the matrix or vector.
var CM = require('eigenjs').CMatrix
, cmat = new CM(3, 3).set([
1, 2, 3,
4, 5, 6,
7, 8, 9
]);
cmat.visit(function(value, row, col) {
console.log('cmat(%d, %d) = %s', row, col, value);
});
cmat(0, 0) = (1,0)
cmat(1, 0) = (4,0)
cmat(2, 0) = (7,0)
cmat(0, 1) = (2,0)
cmat(1, 1) = (5,0)
cmat(2, 1) = (8,0)
cmat(0, 2) = (3,0)
cmat(1, 2) = (6,0)
cmat(2, 2) = (9,0)
cmat.equals(cmat)
cmat.equals(cvec)
cmat.equals(crvec)
cmat.equals(cmblock)
cmat.equals(cvblock)
cmat.equals(crvblock)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat1 = new CM(2, 2)
, cmat2 = new CM(2, 2)
, cmat3 = new CM(2, 2);
cmat1.set([
C(1,1), C(2,2),
C(3,3), C(4,4)
]);
cmat2.set([
C(1,0), C(2,0),
C(3,0), C(4,0)
]);
cmat3.set([
C(0,1), C(0,2),
C(0,3), C(0,4)
]);
console.log(cmat1.equals(cmat2.add(cmat3)));
true
cmat.isApprox(cmat, [prec = 1e-12])
cmat.isApprox(cvec, [prec = 1e-12])
cmat.isApprox(crvec, [prec = 1e-12])
cmat.isApprox(cmblock, [prec = 1e-12])
cmat.isApprox(cvblock, [prec = 1e-12])
cmat.isApprox(crvblock, [prec = 1e-12])
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat1 = new CM(2, 2)
, cmat2 = new CM(2, 2);
cmat1.set([
C(1,1), C(3,3),
C(5,5), C(7,7)
]).diva(C(11,11));
cmat2.set([
C(0.091,0), C(0.273,0),
C(0.455,0), C(0.636,0)
]);
console.log(cmat1.isApprox(cmat2, 1e-3));
true
cmat.isSquare()
var CM = require('eigenjs').CMatrix
, cmat1 = new CM(4, 4)
, cmat2 = new CM(3, 2);
console.log(cmat1.isSquare());
console.log(cmat2.isSquare());
true
false
cmat.isZero([prec = 1e-12])
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 3).set([
0, 0 , 0.0001,
0, C(0, 0.0007), 0
]);
console.log(cmat.isZero());
console.log(cmat.isZero(1e-3));
false
true
cmat.isOnes([prec = 1e-12])
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CM = Eigen.CMatrix
, cmat = new CM(2, 3).set([
1, 1, 1.0001 ,
1, 0.9997, C(1, 0.0001)
]);
console.log(cmat.isOnes());
console.log(cmat.isOnes(1e-3));
false
true
cmat.isIdentity([prec = 1e-12])
var CM = require('eigenjs').CMatrix
, cmat = new CM(3, 3).set([
1, 0, 0.0001,
0, 0.9997, 0,
0, 0, 1
]);
console.log(cmat.isIdentity());
console.log(cmat.isIdentity(1e-3));
false
true
cmat.isDiagonal([prec = 1e-12])
var CM = require('eigenjs').CMatrix
, cmat = new CM(3, 3).set([
1e+04, 0, 1,
0, 1e+04, 0,
0, 0, 1e+04
]);
console.log(cmat.isDiagonal());
console.log(cmat.isDiagonal(1e-3));
false
true
cmat.allFinite()
Returns true if *this contains only finite numbers, i.e., no NaN and no +/-INF values.
var CM = require('eigenjs').CMatrix
, cmat = new CM.Random(3, 3);
console.log('cmat = \n%s\n%s\n', cmat, cmat.allFinite());
cmat.set(0, 0, Infinity);
console.log('cmat = \n%s\n%s', cmat, cmat.allFinite());
cmat =
(-0.0193897,0.117036) (-0.236475,-0.431972) (0.261242,0.687658)
(-0.982734,-0.815806) (-0.153287,-0.292975) (-0.532892,-0.314321)
(0.750476,-0.742562) (-0.0286768,0.0286941) (-0.790602,0.352619)
true
cmat =
(inf,0) (-0.236475,-0.431972) (0.261242,0.687658)
(-0.982734,-0.815806) (-0.153287,-0.292975) (-0.532892,-0.314321)
(0.750476,-0.742562) (-0.0286768,0.0286941) (-0.790602,0.352619)
false
cmat.hasNaN()
Returns true if *this contains at least one Not A Number (NaN).
var CM = require('eigenjs').CMatrix
, cmat = new CM.Zero(3, 3);
console.log('cmat = \n%s\n%s\n', cmat, cmat.hasNaN());
cmat.set(1, 1, NaN);
console.log('cmat = \n%s\n%s', cmat, cmat.hasNaN());
cmat =
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
false
cmat =
(0,0) (0,0) (0,0)
(0,0) (nan,0) (0,0)
(0,0) (0,0) (0,0)
true
cmat.partialPivLu()
Returns the partial-pivoting LU decomposition of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, cpplu = cmat.partialPivLu();
console.log('P = \n%s\n', cpplu.permutationP());
console.log('L = \n%s\n', cpplu.matrixL());
console.log('U = \n%s', cpplu.matrixU());
P =
(0,0) (0,0) (1,0)
(0,0) (1,0) (0,0)
(1,0) (0,0) (0,0)
L =
(1,0) (0,0) (0,0)
(0.8,0) (1,0) (0,0)
(0.2,0) (-1,-0) (1,0)
U =
(5,0) (6,0) (3,0)
(0,0) (-2.8,0) (3.6,0)
(0,0) (0,0) (8,0)
cmat.fullPivLu()
Returns the full-pivoting LU decomposition of *this.
var CM = require('eigenjs').CMatrix
, cmat = new CM(2, 4).set([
1, 1, 1, 3,
1, 2, -1, 4
])
, cfplu = cmat.fullPivLu();
console.log('P = \n%s\n', cfplu.permutationP());
console.log('L = \n%s\n', cfplu.matrixL());
console.log('U = \n%s\n', cfplu.matrixU());
console.log('Q = \n%s', cfplu.permutationQ());
P =
(0,0) (1,0)
(1,0) (0,0)
L =
(1,0) (0,0)
(0.75,0) (1,0)
U =
(4,0) (-1,0) (2,0) (1,0)
(0,0) (1.75,0) (-0.5,0) (0.25,0)
Q =
(0,0) (0,0) (0,0) (1,0)
(0,0) (0,0) (1,0) (0,0)
(0,0) (1,0) (0,0) (0,0)
(1,0) (0,0) (0,0) (0,0)
cmat.toString([options])
- options
Object
- precision
Number
Default=6
. The number of digits for floating point values. - fullPrecision
Booleam
Default=false
. If set to true, then the number of digits will be computed to match the full precision of each floating-point type. - dontAlignCols
Booleam
Default=false
. If set to true, it allows to disable the alignment of columnt, resulting in faster code. - coeffSeparator
String
Default=' '
. The string printed between two coefficients of the same row. - rowSeparator
String
Default=''
. The string printed between two rows. - rowPrefix
String
Default=''
. The string printed at the beginning of each row. - rowSuffix
String
Default=''
. The string printed at the end of each row. - matPrefix
String
Default=''
. The string printed at the beginning of the matrix. - matSuffix
String
Default=''
. The string printed at the end of the matrix.
- precision
var CM = require('eigenjs').CMatrix
, cmat = new CM.Random(3, 3)
, octavefmt = {
coeffSeparator: ", "
, rowSeparator: ";\n"
, rowPrefix: "["
, rowSuffix: "]"
};
console.log('cmat =\n%s\n', cmat.toString());
console.log('cmat =\n' + cmat.toString(octavefmt));
cmat =
(-0.881059,0.0362337) (-0.272438,-0.865992) (-0.230511,-0.192664)
(0.979223,-0.201546) (-0.723588,0.651508) (-0.105755,0.579535)
(0.624409,0.438373) (-0.109684,0.538095) (0.244085,0.332142)
cmat =
[(-0.881059,0.0362337), (-0.272438,-0.865992), (-0.230511,-0.192664)];
[ (0.979223,-0.201546), (-0.723588,0.651508), (-0.105755,0.579535)];
[ (0.624409,0.438373), (-0.109684,0.538095), (0.244085,0.332142)]
Vector
Vector Class Methods
Vector(mat)
Vector(vec)
Vector(rvec)
Vector(mblock)
Vector(vblock)
Vector(rvblock)
var V = require('eigenjs').Vector
, vec = new V.Random(3)
, vec2 = new V(vec);
console.log('vec = \n%s\n', vec);
console.log('vec2 = \n%s', vec2);
vec =
-0.777518
0.25226
-0.262954
vec2 =
-0.777518
0.25226
-0.262954
Vector(rows)
var V = require('eigenjs').Vector
, vec = new V(3);
console.log('vec = \n%s', vec);
vec =
0
0
0
Vector(scalar_array)
var V = require('eigenjs').Vector
, vec = new V([1,
2,
3]);
console.log('vec = \n%s', vec);
vec =
1
2
3
Vector.Constant(rows, scalar)
Vector.Constant(rows, comp)
var V = require('eigenjs').Vector
, vec = V.Constant(4, 0.6);
console.log('vec = \n%s', vec);
vec =
0.6
0.6
0.6
0.6
Vector.LinSpaced(size, low, high)
Sets a linearly space vector.
var V = require('eigenjs').Vector
, vec = V.LinSpaced(5, 0, 1);
console.log('vec = \n%s', vec);
vec =
0
0.25
0.5
0.75
1
Vector Instance Methods
vec.set(row, scalar)
var V = require('eigenjs').Vector
, vec = new V(3);
vec.set(0, 1);
vec.set(1, 2);
vec.set(2, 3);
console.log('vec = \n%s', vec);
vec =
1
2
3
vec.set(scalar_array)
var V = require('eigenjs').Vector
, vec = new V(3);
vec.set([1,
2,
3]);
console.log('vec = \n%s', vec);
vec =
1
2
3
vec.get(row)
var V = require('eigenjs').Vector
, vec = new V([1,
2,
3]);
console.log(vec.get(0));
console.log(vec.get(1));
console.log(vec.get(2));
1
2
3
vec.setLinSpaced(low, high)
Sets a linearly space vector.
var V = require('eigenjs').Vector
, vec = new V.Zero(5);
console.log('vec = \n%s\n', vec);
vec.setLinSpaced(0, 1);
console.log('vec = \n%s', vec);
vec =
0
0
0
0
0
vec =
0
0.25
0.5
0.75
1
vec.setLinSpaced(size, low, high)
Sets a linearly space vector.
var V = require('eigenjs').Vector
, vec = new V.Random(3);
console.log('vec = \n%s\n', vec);
vec.setLinSpaced(5, 0, 1);
console.log('vec = \n%s', vec);
vec =
-0.498866
-0.440048
0.118123
vec =
0
0.25
0.5
0.75
1
vec.block(startRow, blockRows)
var V = require('eigenjs').Vector
, vec = new V([1,
2,
3,
4])
, vblock = vec.block(1, 2);
console.log('vblock = \n%s', vblock);
vblock =
2
3
vec.head(n)
var V = require('eigenjs').Vector
, vec = new V([1,
2,
3,
4])
, vblock = vec.head(2);
console.log('vblock = \n%s', vblock);
vblock =
1
2
vec.tail(n)
var V = require('eigenjs').Vector
, vec = new V([1,
2,
3,
4])
, vblock = vec.tail(2);
console.log('vblock = \n%s', vblock);
vblock =
3
4
vec.dot(mat)
vec.dot(vec)
vec.dot(rvec)
vec.dot(mblock)
vec.dot(vblock)
vec.dot(rvblock)
vec.dot(cmat)
vec.dot(cvec)
vec.dot(crvec)
vec.dot(cmblock)
vec.dot(cvblock)
vec.dot(crvblock)
Returns the dot product of *this with other.
var V = require('eigenjs').Vector
, vec1 = new V([1,
2,
3])
, vec2 = new V([4,
5,
6]);
console.log(vec1.dot(vec2).toString());
32
vec.asDiagonal()
var V = require('eigenjs').Vector
, vec = new V.Random(3)
, dia = vec.asDiagonal();
console.log('vec = \n%s\n', vec);
console.log('dia = \n%s', dia);
vec =
0.593699
0.299713
-0.718297
dia =
0.593699 0 0
0 0.299713 0
0 0 -0.718297
vec.normalize()
var V = require('eigenjs').Vector
, vec = new V([
1,
2,
3
]);
vec.normalize();
console.log('vec = \n%s', vec);
vec =
0.267261
0.534522
0.801784
vec.maxCoeff()
var V = require('eigenjs').Vector
, vec = new V.Random(3);
console.log('vec = \n%s\n', vec);
console.log('max = %d', vec.maxCoeff());
vec =
0.604974
-0.210128
0.37608
max = 0.6049735153117093
vec.maxCoeff(obj)
- obj
Object
var V = require('eigenjs').Vector
, vec = new V.Random(3)
, obj = {};
console.log('vec = \n%s\n', vec);
console.log('max = %d', vec.maxCoeff(obj));
console.log('obj = %s', JSON.stringify(obj));
vec =
-0.887644
-0.63168
-0.644859
max = -0.631679946385175
obj = {"maxCoeff":-0.631679946385175,"rowId":1,"colId":0}
vec.maxCoeff(func)
- func
Function
var V = require('eigenjs').Vector
, vec = new V.Random(3)
, func = function(rowId, colId) {
console.log('rowId = %d, colId = %d', rowId, colId);
};
console.log('vec = \n%s\n', vec);
console.log('max = %d', vec.maxCoeff(func));
vec =
-0.006325
-0.304345
0.875084
rowId = 2, colId = 0
max = 0.8750841114088352
vec.minCoeff()
var V = require('eigenjs').Vector
, vec = new V.Random(3);
console.log('vec = \n%s\n', vec);
console.log('min = %d', vec.minCoeff());
vec =
0.311621
-0.59179
-0.210911
min = -0.5917897846511517
vec.minCoeff(obj)
- obj
Object
var V = require('eigenjs').Vector
, vec = new V.Random(3)
, obj = {};
console.log('vec = \n%s\n', vec);
console.log('min = %d', vec.minCoeff(obj));
console.log('obj = %s', JSON.stringify(obj));
vec =
0.413097
0.9239
-0.0150985
min = -0.015098494950262165
obj = {"minCoeff":-0.015098494950262165,"rowId":2,"colId":0}
vec.minCoeff(func)
- func
Function
var V = require('eigenjs').Vector
, vec = new V.Random(3)
, func = function(rowId, colId) {
console.log('rowId = %d, colId = %d', rowId, colId);
};
console.log('vec = \n%s\n', vec);
console.log('min = %d', vec.minCoeff(func));
vec =
-0.277781
-0.668038
0.286223
rowId = 1, colId = 0
min = -0.668037947112712
Complex Vector
Complex Vector Class Methods
CVector(mat)
CVector(vec)
CVector(rvec)
CVector(mblock)
CVector(vblock)
CVector(rvblock)
CVector(cmat)
CVector(cvec)
CVector(crvec)
CVector(cmblock)
CVector(cvblock)
CVector(crvblock)
var CV = require('eigenjs').CVector
, cvec = new CV.Random(3)
, cvec2 = new CV(cvec);
console.log('cvec = \n%s\n', cvec);
console.log('cvec2 = \n%s', cvec2);
cvec =
(0.97863,-0.172027)
(0.743826,-0.517891)
(-0.194503,0.984235)
cvec2 =
(0.97863,-0.172027)
(0.743826,-0.517891)
(-0.194503,0.984235)
CVector(rows)
var CV = require('eigenjs').CVector
, cvec = new CV(3);
console.log('cvec = \n%s', cvec);
cvec =
0
0
0
CVector(comp_array)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CV = Eigen.Vector
, cvec = new CV([ 1 ,
C(2, 4),
3 ]);
console.log('cvec = \n%s', cvec);
cvec =
(1,0)
(2,4)
(3,0)
CVector.Constant(rows, scalar)
CVector.Constant(rows, comp)
var CV = require('eigenjs').CVector
, cvec = CV.Constant(4, 0.6);
console.log('cvec = \n%s', cvec);
cvec =
(0.6,0)
(0.6,0)
(0.6,0)
(0.6,0)
Complex Vector Instance Methods
cvec.set(row, comp)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CV = Eigen.CVector
, cvec = new CV(3);
cvec.set(0, C(1 ));
cvec.set(1, C(2, 4));
cvec.set(2, 3 );
console.log('cvec = \n%s', cvec);
cvec =
(1,0)
(2,4)
(3,0)
cvec.set(comp_array)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CV = Eigen.CVector
, cvec = new CV(3);
cvec.set([ 1 ,
C(2, 4),
3 ]);
console.log('cvec = \n%s', cvec);
cvec =
(1,0)
(2,4)
(3,0)
cvec.get(row)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CV = Eigen.CVector
, cvec = new CV([ 1 ,
C(2, 4),
3 ]);
console.log(vec.get(0).toString());
console.log(vec.get(1).toString());
console.log(vec.get(2).toString());
(1,0)
(2,4)
(3,0)
cvec.block(startRow, blockRows)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CV = Eigen.CVector
, cvec = new CV([ 1 ,
2 ,
C(3 ),
C(4, 0)])
, cvblock = cvec.block(1, 2);
console.log('cvblock = \n%s', cvblock);
cvblock =
(2,0)
(3,0)
cvec.head(n)
var CV = require('eigenjs').CVector
, cvec = new CV([ 1 ,
2 ,
C(3 ),
C(4, 0)])
, cvblock = cvec.head(2);
console.log('cvblock = \n%s', cvblock);
cvblock =
(1,0)
(2,0)
cvec.tail(n)
var CV = require('eigenjs').CVector
, cvec = new CV([ 1 ,
2 ,
C(3 ),
C(4, 0)])
, cvblock = cvec.tail(2);
console.log('cvblock = \n%s', cvblock);
cvblock =
(3,0)
(4,0)
cvec.dot(mat)
cvec.dot(vec)
cvec.dot(rvec)
cvec.dot(mblock)
cvec.dot(vblock)
cvec.dot(rvblock)
cvec.dot(cmat)
cvec.dot(cvec)
cvec.dot(crvec)
cvec.dot(cmblock)
cvec.dot(cvblock)
cvec.dot(crvblock)
Returns the dot product of *this with other.
This function returns the hermitian (sesquilinear) dot product, conjugate-linear in the first variable and linear in the second variable.
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CV = Eigen.CVector
, cvec1 = new CV([C(1, 1),
C(2, 2),
C(3, 3)])
, cvec2 = new CV([4,
5,
6]);
console.log(cvec1.dot(cvec2).toString());
(32,-32)
cvec.asDiagonal()
var CV = require('eigenjs').CVecotr
, cvec = new CV.Random(3)
, dia = cvec.asDiagonal();
console.log('cvec = \n%s\n', cvec);
console.log('dia = \n%s', dia);
cvec =
(-0.350871,0.918551)
(0.0934938,-0.649058)
(-0.725789,-0.339967)
dia =
(-0.350871,0.918551) (0,0) (0,0)
(0,0) (0.0934938,-0.649058) (0,0)
(0,0) (0,0) (-0.725789,-0.339967)
cvec.normalize()
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CV = Eigen.CVector
, cvec = new CV([
1 ,
C(2, 3),
4
]);
cvec.normalize();
console.log('cvec = \n%s', cvec);
cvec =
(0.182574,0)
(0.365148,0.547723)
(0.730297,0)
Row Vector
Row Vector Class Methods
RowVector(mat)
RowVector(vec)
RowVector(rvec)
RowVector(mblock)
RowVector(vblock)
RowVector(rvblock)
var RV = require('eigenjs').RowVector
, rvec = new RV.Random(3)
, rvec2 = new RV(rvec);
console.log('rvec = \n%s\n', rvec);
console.log('rvec2 = \n%s', rvec2);
rvec =
-0.0369638 0.749797 -0.15956
rvec2 =
-0.0369638 0.749797 -0.15956
RowVector(cols)
var RV = require('eigenjs').RowVector
, rvec = new RV(3);
console.log('rvec = \n%s', rvec);
rvec =
0 0 0
RowVector(scalar_array)
var RV = require('eigenjs').RowVector
, rvec = new RV([1, 2, 3]);
console.log('rvec = \n%s', rvec);
rvec =
1 2 3
RowVector.Constant(cols, scalar)
RowVector.Constant(cols, comp)
var RV = require('eigenjs').RVector
, rvec = RV.Constant(4, 0.6);
console.log('rvec = \n%s', rvec);
rvec =
0.6 0.6 0.6 0.6
RowVector.LinSpaced(size, low, high)
Sets a linearly space vector.
var RV = require('eigenjs').RowVector
, rvec = RV.LinSpaced(5, 1, 0);
console.log('rvec = \n%s', rvec);
rvec =
1 0.75 0.5 0.25 0
Row Vector Instance Methods
rvec.set(col, scalar)
var RV = require('eigenjs').RowVector
, rvec = new RV(3);
rvec.set(0, 1);
rvec.set(1, 2);
rvec.set(2, 3);
console.log('rvec = \n%s', rvec);
rvec =
1 2 3
rvec.set(scalar_array)
var RV = require('eigenjs').RowVector
, rvec = new RV(3);
rvec.set([1, 2, 3]);
console.log('rvec = \n%s', rvec);
rvec =
1 2 3
rvec.get(col)
var RV = require('eigenjs').RowVector
, rvec = new RV([1, 2, 3]);
console.log(rvec.get(0));
console.log(rvec.get(1));
console.log(rvec.get(2));
1
2
3
rvec.setLinSpaced(low, high)
Sets a linearly space vector.
var RV = require('eigenjs').RowVector
, rvec = new RV.Zero(5);
console.log('rvec = \n%s\n', rvec);
rvec.setLinSpaced(1, 0);
console.log('rvec = \n%s', rvec);
rvec =
0 0 0 0 0
rvec =
1 0.75 0.5 0.25 0
rvec.setLinSpaced(size, low, high)
Sets a linearly space vector.
var RV = require('eigenjs').RowVector
, rvec = new RV.Random(3);
console.log('rvec = \n%s\n', rvec);
rvec.setLinSpaced(5, 1, 0);
console.log('rvec = \n%s', rvec);
rvec =
0.829713 0.985904 0.0914511
rvec =
1 0.75 0.5 0.25 0
rvec.block(startCol, blockCols)
var RV = require('eigenjs').RowVector
, rvec = new RV([1, 2, 3, 4])
, rvblock = rvec.block(1, 2);
console.log('rvblock = \n%s', rvblock);
rvblock =
2 3
rvec.head(n)
var RV = require('eigenjs').RowVector
, rvec = new RV([1, 2, 3, 4])
, rvblock = rvec.head(2);
console.log('rvblock = \n%s', rvblock);
rvblock =
1 2
rvec.tail(n)
var RV = require('eigenjs').RowVector
, rvec = new RV([1, 2, 3, 4])
, rvblock = rvec.tail(2);
console.log('rvblock = \n%s', rvblock);
rvblock =
3 4
rvec.dot(mat)
rvec.dot(vec)
rvec.dot(rvec)
rvec.dot(mblock)
rvec.dot(vblock)
rvec.dot(rvblock)
rvec.dot(cmat)
rvec.dot(cvec)
rvec.dot(crvec)
rvec.dot(cmblock)
rvec.dot(cvblock)
rvec.dot(crvblock)
Returns the dot product of *this with other.
var RV = require('eigenjs').RowVector
, rvec1 = new RV([1, 2, 3])
, rvec2 = new RV([4, 5, 6]);
console.log(rvec1.dot(rvec2).toString());
32
rvec.asDiagonal()
var RV = require('eigenjs').RowVector
, rvec = new RV.Random(3)
, dia = rvec.asDiagonal();
console.log('rvec = \n%s\n', rvec);
console.log('dia = \n%s', dia);
rvec =
0.00429723 0.223465 -0.221164
dia =
0.00429723 0 0
0 0.223465 0
0 0 -0.221164
rvec.normalize()
var RV = require('eigenjs').RVector
, rvec = new RV([1, 2, 3]);
rvec.normalize();
console.log('rvec = \n%s', rvec);
rvec =
0.267261 0.534522 0.801784
rvec.maxCoeff()
var RV = require('eigenjs').RowVector
, rvec = new RV.Random(3);
console.log('rvec = \n%s\n', rvec);
console.log('max = %d', rvec.maxCoeff());
rvec =
-0.487994 0.283088 -0.14679
max = 0.28308759503210323
rvec.maxCoeff(obj)
- obj
Object
var RV = require('eigenjs').RowVector
, rvec = new RV.Random(3)
, obj = {};
console.log('rvec = \n%s\n', rvec);
console.log('max = %d', rvec.maxCoeff(obj));
console.log('obj = %s', JSON.stringify(obj));
rvec =
0.402709 0.332409 0.800923
max = 0.8009226330560273
obj = {"maxCoeff":0.8009226330560273,"rowId":0,"colId":2}
rvec.maxCoeff(func)
- func
Function
var RV = require('eigenjs').RowVector
, rvec = new RV.Random(3)
, func = function(rowId, colId) {
console.log('rowId = %d, colId = %d', rowId, colId);
};
console.log('rvec = \n%s\n', rvec);
console.log('max = %d', rvec.maxCoeff(func));
rvec =
0.713395 0.0274691 -0.326461
rowId = 0, colId = 0
max = 0.7133948633975324
rvec.minCoeff()
var RV = require('eigenjs').RowVector
, rvec = new RV.Random(3);
console.log('rvec = \n%s\n', rvec);
console.log('min = %d', rvec.minCoeff());
rvec =
0.349846 -0.129927 0.316636
min = -0.1299270163895222
rvec.minCoeff(obj)
- obj
Object
var RV = require('eigenjs').RowVector
, rvec = new RV.Random(3)
, obj = {};
console.log('rvec = \n%s\n', rvec);
console.log('min = %d', rvec.minCoeff(obj));
console.log('obj = %s', JSON.stringify(obj));
rvec =
0.451323 -0.614237 0.512448
min = -0.6142373744464653
obj = {"minCoeff":-0.6142373744464653,"rowId":0,"colId":1}
rvec.minCoeff(func)
- func
Function
var RV = require('eigenjs').RowVector
, rvec = new RV.Random(3)
, func = function(rowId, colId) {
console.log('rowId = %d, colId = %d', rowId, colId);
};
console.log('rvec = \n%s\n', rvec);
console.log('min = %d', rvec.minCoeff(func));
rvec =
-0.816445 0.0135587 -0.118738
rowId = 0, colId = 0
min = -0.8164447219187602
Complex Row Vector
Complex Row Vector Class Methods
CRowVector(mat)
CRowVector(vec)
CRowVector(rvec)
CRowVector(mblock)
CRowVector(vblock)
CRowVector(rvblock)
CRowVector(cmat)
CRowVector(cvec)
CRowVector(crvec)
CRowVector(cmblock)
CRowVector(cvblock)
CRowVector(crvblock)
var CRV = require('eigenjs').CRowVector
, crvec = new CRV.Random(3)
, crvec2 = new CRV(crvec);
console.log('crvec = \n%s\n', crvec);
console.log('crvec2 = \n%s', crvec2);
crvec =
(-0.456363,-0.0965678) (0.985458,0.584867) (-0.136223,0.491867)
crvec2 =
(-0.456363,-0.0965678) (0.985458,0.584867) (-0.136223,0.491867)
CRowVector(cols)
var CRV = require('eigenjs').CRowVector
, crvec = new CRV(3);
console.log('crvec = \n%s', crvec);
cvec =
(0,0) (0,0) (0,0)
CRowVector(comp_array)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CRV = Eigen.CRowVector
, crvec = new CRV([1, C(2, 4), 3]);
console.log('crvec = \n%s', crvec);
crvec =
(1,0) (2,4) (3,0)
CRowVector.Constant(cols, scalar)
CRowVector.Constant(cols, comp)
var CRV = require('eigenjs').CRVector
, crvec = CRV.Constant(4, 0.6);
console.log('crvec = \n%s', crvec);
crvec =
(0.6,0) (0.6,0) (0.6,0) (0.6,0)
Complex Row Vector Instance Methods
crvec.set(col, comp)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CRV = Eigen.CRowVector
, crvec = new CRV(3);
crvec.set(0, C(1 ));
crvec.set(1, C(2, 4));
crvec.set(2, 3 );
console.log('crvec = \n%s', crvec);
cvec =
(1,0) (2,4) (3,0)
crvec.set(comp_array)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CRV = Eigen.CRowVector
, crvec = new CRV(3);
crvec.set([1, C(2, 4), 3]);
console.log('crvec = \n%s', crvec);
crvec =
(1,0) (2,4) (3,0)
crvec.get(col)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CRV = Eigen.CRowVector
, crvec = new CRV([1, C(2, 4), 3]);
console.log(crvec.get(0).toString());
console.log(crvec.get(1).toString());
console.log(crvec.get(2).toString());
(1,0)
(2,4)
(3,0)
crvec.block(startCol, blockCols)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CRV = Eigen.CRowVector
, crvec = new CRV([1, 2, C(3), C(4, 0)])
, crvblock = crvec.block(1, 2);
console.log('crvblock = \n%s', crvblock);
crvblock =
(2,0) (3,0)
crvec.head(n)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CRV = Eigen.CRowVector
, crvec = new CRV([1, 2, C(3), C(4, 0)])
, crvblock = crvec.head(2);
console.log('crvblock = \n%s', crvblock);
crvblock =
(1,0) (2,0)
crvec.tail(n)
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CRV = Eigen.CRowVector
, crvec = new CRV([1, 2, C(3), C(4, 0)])
, crvblock = crvec.tail(2);
console.log('crvblock = \n%s', crvblock);
crvblock =
(3,0) (4,0)
crvec.dot(mat)
crvec.dot(vec)
crvec.dot(rvec)
crvec.dot(mblock)
crvec.dot(vblock)
crvec.dot(rvblock)
crvec.dot(cmat)
crvec.dot(cvec)
crvec.dot(crvec)
crvec.dot(cmblock)
crvec.dot(cvblock)
crvec.dot(crvblock)
Returns the dot product of *this with other.
This function returns the hermitian (sesquilinear) dot product, conjugate-linear in the first variable and linear in the second variable.
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CRV = Eigen.CRowVector
, crvec1 = new CRV([C(1, 1), C(2, 2), C(3, 3)])
, crvec2 = new CRV([4, 5, 6]);
console.log(crvec1.dot(crvec2).toString());
(32,-32)
crvec.asDiagonal()
var Eigen = require('eigenjs')
, CRV = Eigen.CRowVector
, crvec = new CRV.Random(3)
, dia = crvec.asDiagonal();
console.log('crvec = \n%s\n', crvec);
console.log('dia = \n%s', dia);
crvec =
(-0.52811,0.0530528) (-0.340944,-0.248457) (0.185028,-0.228998)
dia =
(-0.52811,0.0530528) (0,0) (0,0)
(0,0) (-0.340944,-0.248457) (0,0)
(0,0) (0,0) (0.185028,-0.228998)
crvec.normalize()
var Eigen = require('eigenjs')
, C = Eigen.Complex
, CRV = Eigen.CRowVector
, crvec = new CRV([1, C(2, 3), 4]);
crvec.normalize();
console.log('crvec = \n%s', crvec);
crvec =
(0.182574,0) (0.365148,0.547723) (0.730297,0)
Matrix Block
Matrix Block Class Methods
MatrixBlock(mat, startRow, startCol, blockRows, blockCols)
MatrixBlock(mblock, startRow, startCol, blockRows, blockCols)
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, MB = Eigen.MatrixBlock
, mat = new M.Random(4, 4)
, mblock = new MB(mat, 1, 1, 2, 2);
console.log('mat = \n%s', mat);
console.log('mblock = \n%s', mblock);
mat =
0.63505 0.904788 -0.727407 0.187778
-0.709806 0.764849 0.467046 -0.0105777
0.295743 0.813348 -0.350211 0.221291
0.557679 -0.0634692 -0.000702816 -0.76436
mblock =
0.764849 0.467046
0.813348 -0.350211
Matrix Block Instance Methods
Complex Matrix Block
Complex Matrix Block Class Methods
CMatrixBlock(cmat, startRow, startCol, blockRows, blockCols)
CMatrixBlock(cmblock, startRow, startCol, blockRows, blockCols)
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CMB = Eigen.CMatrixBlock
, cmat = new CM.Random(3, 3)
, cmblock = new CMB(cmat, 1, 1, 2, 1);
console.log('cmat = \n%s', cmat);
console.log('cmblock = \n%s', cmblock);
cmat =
(0.24353,-0.983476) (0.689103,-0.238167) (0.931696,-0.989139)
(0.72236,0.70887) (-0.870838,-0.17097) (-0.463351,0.45267)
(-0.0298291,0.662265) (0.513237,-0.0206502) (0.0326769,-0.799212)
cmblock =
(-0.870838,-0.17097)
(0.513237,-0.0206502)
Complex Matrix Block Instance Methods
Vector Block
Vector Block Class Methods
VectorBlock(vec, startRow, blockRows)
VectorBlock(vblock, startRow, blockRows)
var Eigen = require('eigenjs')
, V = Eigen.Vector
, VB = Eigen.VectorBlock
, vec = new V.Random(4)
, vblock = new VB(vec, 1, 2);
console.log('vec = \n%s', vec);
console.log('vblock = \n%s', vblock);
vec =
0.588843
0.686789
0.856138
-0.895627
vblock =
0.686789
0.856138
Vector Block Instance Methods
Complex Vector Block
Complex Vector Block Class Methods
CVectorBlock(cvec, startRow, blockRows)
CVectorBlock(cvblock, startRow, blockRows)
var Eigen = require('eigenjs')
, CV = Eigen.CVector
, CVB = Eigen.CVectorBlock
, cvec = new CV.Random(4)
, cvblock = new CVB(cvec, 1, 2);
console.log('cvec = \n%s', cvec);
console.log('cvblock = \n%s', cvblock);
cvec =
(0.152345,0.457992)
(-0.536544,0.301383)
(-0.65206,0.819627)
(-0.523377,-0.399041)
cvblock =
(-0.536544,0.301383)
(-0.65206,0.819627)
Complex Vector Block Instance Methods
Row Vector Block
Row Vector Block Class Methods
RowVectorBlock(rvec, startCol, blockCols)
RowVectorBlock(rvblock, startCol, blockCols)
var Eigen = require('eigenjs')
, RV = Eigen.RowVector
, RVB = Eigen.RowVectorBlock
, rvec = new RV.Random(4)
, rvblock = new RVB(rvec, 1, 2);
console.log('rvec = \n%s', rvec);
console.log('rvblock = \n%s', rvblock);
rvec =
0.922803 -0.45235 -0.640183 0.439847
rvblock =
-0.45235 -0.640183
Row Vector Block Instance Methods
Complex Row Vector Block
Complex Row Vector Block Class Methods
CRowVectorBlock(crvec, startCol, blockCols)
CRowVectorBlock(crvblock, startCol, blockCols)
var Eigen = require('eigenjs')
, CRV = Eigen.CRowVector
, CRVB = Eigen.CRowVectorBlock
, crvec = new CRV.Random(4)
, crvblock = new CRVB(crvec, 1, 2);
console.log('crvec = \n%s', crvec);
console.log('crvblock = \n%s', crvblock);
crvec =
(0.707337,0.220289) (0.397833,0.371915) (0.782186,0.199594) (0.575888,0.951467)
crvblock =
(0.397833,0.371915) (0.782186,0.199594)
Complex Row Vector Block Instance Methods
Partial Pivoting LU
This class represents a LU decomposition of a square invertible matrix, with partial pivoting: the matrix A is decomposed as PA = LU where L is unit-lower-triangular, U is upper-triangular, and P is a permutation matrix.
Partial Pivoting LU Class Methods
PartialPivLU(mat)
PartialPivLU(mblock)
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, PPLU = Eigen.PartialPivLU
, mat = new M(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, pplu = new PPLU(mat)
, P = pplu.permutationP()
, L = pplu.matrixL()
, U = pplu.matrixU();
console.log('%s', P.inverse().mula(L).mula(U));
1 4 5
4 2 6
5 6 3
Partial Pivoting LU Instance Methods
pplu.permutationP()
Returns the permutation matrix P.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, PPLU = Eigen.PartialPivLU
, mat = new M(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, pplu = new PPLU(mat);
console.log('P = \n%s', pplu.permutationP());
P =
0 0 1
0 1 0
1 0 0
pplu.matrixL()
Returns the unit-lower-triangular matrix L.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, PPLU = Eigen.PartialPivLU
, mat = new M(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, pplu = new PPLU(mat);
console.log('L = \n%s', pplu.matrixL());
L =
1 0 0
0.8 1 0
0.2 -1 1
pplu.matrixU()
Returns the upper-triangular matrix U.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, PPLU = Eigen.PartialPivLU
, mat = new M(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, pplu = new PPLU(mat);
console.log('U = \n%s', pplu.matrixU());
U =
5 6 3
0 -2.8 3.6
0 0 8
pplu.determinant()
Returns the determinant of the matrix of which *this is the LU decomposition. It has only linear complexity (that is, O(n) where n is the dimension of the square matrix) as the LU decomposition has already been computed.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, PPLU = Eigen.PartialPivLU
, mat = new M(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, pplu = new PPLU(mat);
console.log('%d', mat.determinant());
console.log('%d', pplu.determinant());
112
112
pplu.inverse()
Returns the inverse of the matrix of which *this is the LU decomposition.
The matrix being decomposed here is assumed to be invertible. If you need to check for invertibility, use class FullPivLU instead.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, PPLU = Eigen.PartialPivLU
, mat = new M(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, pplu = new PPLU(mat);
console.log('%s', pplu.inverse().equals(mat.inverse()));
true
pplu.solve(mat)
pplu.solve(vec)
This method returns the solution x to the equation Ax=b, where A is the matrix of which *this is the LU decomposition.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, V = Eigen.Vector
, PPLU = Eigen.PartialPivLU
, mat = new M(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, b = new V([
24,
26,
26
])
, pplu = new PPLU(mat);
console.log('x = \n%s', pplu.solve(b));
x =
1
2
3
Complex Partial Pivoting LU
This class represents a LU decomposition of a square invertible matrix, with partial pivoting: the matrix A is decomposed as PA = LU where L is unit-lower-triangular, U is upper-triangular, and P is a permutation matrix.
Complex Partial Pivoting LU Class Methods
CPartialPivLU(cmat)
CPartialPivLU(cmblock)
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CPPLU = Eigen.CPartialPivLU
, cmat = new CM(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, cpplu = new CPPLU(cmat)
, P = cpplu.permutationP()
, L = cpplu.matrixL()
, U = cpplu.matrixU();
console.log('%s', P.inverse().mula(L).mula(U));
(1,0) (4,0) (5,0)
(4,0) (2,0) (6,0)
(5,0) (6,0) (3,0)
Complex Partial Pivoting LU Instance Methods
cpplu.permutationP()
Returns the permutation matrix P.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CPPLU = Eigen.CPartialPivLU
, cmat = new CM(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, cpplu = new CPPLU(cmat);
console.log('P = \n%s', cpplu.permutationP());
P =
(0,0) (0,0) (1,0)
(0,0) (1,0) (0,0)
(1,0) (0,0) (0,0)
cpplu.matrixL()
Returns the unit-lower-triangular matrix L.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CPPLU = Eigen.CPartialPivLU
, cmat = new CM(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, cpplu = new CPPLU(cmat);
console.log('L = \n%s', cpplu.matrixL());
L =
(1,0) (0,0) (0,0)
(0.8,0) (1,0) (0,0)
(0.2,0) (-1,-0) (1,0)
cpplu.matrixU()
Returns the upper-triangular matrix U.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CPPLU = Eigen.CPartialPivLU
, cmat = new CM(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, cpplu = new CPPLU(cmat);
console.log('U = \n%s', cpplu.matrixU());
U =
(5,0) (6,0) (3,0)
(0,0) (-2.8,0) (3.6,0)
(0,0) (0,0) (8,0)
cpplu.determinant()
Returns the determinant of the complex matrix of which *this is the LU decomposition. It has only linear complexity (that is, O(n) where n is the dimension of the complex square matrix) as the LU decomposition has already been computed.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CPPLU = Eigen.CPartialPivLU
, cmat = new CM(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, cpplu = new CPPLU(cmat);
console.log('%s', cmat.determinant());
console.log('%s', cpplu.determinant());
(112,-0)
(112,-0)
cpplu.inverse()
Returns the inverse of the complex matrix of which *this is the LU decomposition.
The complex matrix being decomposed here is assumed to be invertible. If you need to check for invertibility, use class CFullPivLU instead.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CPPLU = Eigen.CPartialPivLU
, cmat = new CM(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, cpplu = new CPPLU(cmat);
console.log('%s', cpplu.inverse().equals(cmat.inverse()));
true
cpplu.solve(cmat)
cpplu.solve(cvec)
This method returns the solution x to the equation Ax=b, where A is the matrix of which *this is the LU decomposition.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CV = Eigen.CVector
, CPPLU = Eigen.CPartialPivLU
, cmat = new CM(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, b = new CV([
24,
26,
26
])
, cpplu = new CPPLU(cmat);
console.log('x = \n%s', cpplu.solve(b));
x =
(1,0)
(2,0)
(3,0)
Full Pivoting LU
This class represents a LU decomposition of any matrix, with complete pivoting: the matrix A is decomposed as PAQ = LU where L is unit-lower-triangular, U is upper-triangular, and P and Q are permutation matrices. This is a rank-revealing LU decomposition. The eigenvalues (diagonal coefficients) of U are sorted in such a way that any zeros are at the end.
This decomposition provides the generic approach to solving systems of linear equations, computing the rank, invertibility, inverse, kernel, and determinant.
This LU decomposition is very stable and well tested with large matrices. However there are use cases where the SVD decomposition is inherently more stable and/or flexible. For example, when computing the kernel of a matrix, working with the SVD allows to select the smallest singular values of the matrix, something that the LU decomposition doesn't see.
Full Pivoting LU Class Methods
FullPivLU(mat)
FullPivLU(mblock)
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, FPLU = Eigen.FullPivLU
, mat = new M(3, 5).set([
1, 3, 0, 2, -1,
0, 0, 1, 4, -3,
1, 2, 1, 6, -4
])
, fplu = new FPLU(mat)
, P = fplu.permutationP()
, L = fplu.matrixL()
, U = fplu.matrixU()
, Q = fplu.permutationQ();
console.log('%s', P.inverse().mula(L).mula(U).mula(Q.inverse()));
1 3 0 2 -1
0 0 1 4 -3
1 2 1 6 -4
Full Pivoting LU Instance Methods
fplu.permutationP()
Returns the permutation matrix P.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, FPLU = Eigen.FullPivLU
, mat = new M(3, 5).set([
1, 3, 0, 2, -1,
0, 0, 1, 4, -3,
1, 2, 1, 6, -4
])
, fplu = new FPLU(mat);
console.log('P = \n%s', fplu.permutationP());
P =
0 0 1
1 0 0
0 1 0
fplu.permutationQ()
Returns the permutation matrix Q.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, FPLU = Eigen.FullPivLU
, mat = new M(3, 5).set([
1, 3, 0, 2, -1,
0, 0, 1, 4, -3,
1, 2, 1, 6, -4
])
, fplu = new FPLU(mat);
console.log('Q = \n%s', fplu.permutationQ());
Q =
0 0 1 0 0
0 1 0 0 0
0 0 0 1 0
1 0 0 0 0
0 0 0 0 1
fplu.matrixL()
Returns the unit-lower-triangular matrix L.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, FPLU = Eigen.FullPivLU
, mat = new M(3, 5).set([
1, 3, 0, 2, -1,
0, 0, 1, 4, -3,
1, 2, 1, 6, -4
])
, fplu = new FPLU(mat);
console.log('L = \n%s', fplu.matrixL());
L =
1 0 0
0.333333 1 0
0.666667 -0.571429 1
fplu.matrixU()
Returns the upper-triangular matrix U.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, FPLU = Eigen.FullPivLU
, mat = new M(3, 5).set([
1, 3, 0, 2, -1,
0, 0, 1, 4, -3,
1, 2, 1, 6, -4
])
, fplu = new FPLU(mat);
console.log('U = \n%s', fplu.matrixU());
U =
6 2 1 1 -4
0 2.33333 0.666667 -0.333333 0.333333
0 0 -0.285714 0.142857 -0.142857
fplu.determinant()
Returns the determinant of the matrix of which *this is the LU decomposition. It has only linear complexity (that is, O(n) where n is the dimension of the square matrix) as the LU decomposition has already been computed.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, FPLU = Eigen.FullPivLU
, mat = M.Random(3, 3)
, fplu = new FPLU(mat)
, det = fplu.determinant();
console.log('mat = \n%s\n', mat);
console.log('det = %d', det);
mat =
0.460707 -0.430882 -0.561277
-0.902957 0.15904 0.614972
-0.00347658 0.980629 -0.170248
det = 0.27353337419849527
fplu.inverse()
Returns the inverse of the matrix of which *this is the LU decomposition.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, FPLU = Eigen.FullPivLU
, mat = M.Random(3, 3)
, fplu = new FPLU(mat)
, inv = fplu.inverse();
console.log('%s', inv.isApprox(mat.inverse()));
true
fplu.isInvertible()
Returns true if the matrix of which *this is the LU decomposition is invertible.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, FPLU = Eigen.FullPivLU
, mat = new M(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, fplu = new FPLU(mat);
console.log('%s', fplu.isInvertible());
true
fplu.solve(mat)
fplu.solve(vec)
Returns a solution x to the equation Ax=b, where A is the matrix of which *this is the LU decomposition.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, V = Eigen.Vector
, FPLU = Eigen.FullPivLU
, mat = new M(3, 3).set([
0, 1, 1,
1, 2, 1,
2, 7, 9
])
, b = new V([
1,
2,
3
])
, fplu = new FPLU(mat);
console.log('x = \n%s', fplu.solve(b));
x =
-1
2
-1
fplu.rank()
Returns the rank of the matrix of which *this is the LU decomposition.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, FPLU = Eigen.FullPivLU
, mat = new M(3, 4).set([
2, 1, 0, 1,
0, 2, 1, 0,
2, 3, 1, 1
])
, fplu = new FPLU(mat);
console.log('%d', fplu.rank());
2
fplu.dimensionOfKernel()
Returns the dimension of the kernel of the matrix of which *this is the LU decomposition.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, FPLU = Eigen.FullPivLU
, mat = M(3, 4).set([
1, 1, 0, 2,
1, 2, 0, 3,
2, 3, 0, 5
])
, fplu = new FPLU(mat)
, dim = fplu.dimensionOfKernel();
console.log('dim = %d', dim);
dim = 2
fplu.kernel()
Returns the kernel of the matrix, also called its null-space. The columns of the returned matrix will form a basis of the kernel.
var Eigen = require('eigenjs')
, M = Eigen.Matrix
, FPLU = Eigen.FullPivLU
, mat = M(3, 4).set([
1, 1, 0, 2,
1, 2, 0, 3,
2, 3, 0, 5
])
, fplu = new FPLU(mat)
, ker = fplu.kernel();
console.log('ker = \n%s', ker);
ker =
1 0
1 0
0 1
-1 -0
Complex Full Pivoting LU
This class represents a LU decomposition of any matrix, with complete pivoting: the matrix A is decomposed as PAQ = LU where L is unit-lower-triangular, U is upper-triangular, and P and Q are permutation matrices. This is a rank-revealing LU decomposition. The eigenvalues (diagonal coefficients) of U are sorted in such a way that any zeros are at the end.
This decomposition provides the generic approach to solving systems of linear equations, computing the rank, invertibility, inverse, kernel, and determinant.
This LU decomposition is very stable and well tested with large matrices. However there are use cases where the SVD decomposition is inherently more stable and/or flexible. For example, when computing the kernel of a matrix, working with the SVD allows to select the smallest singular values of the matrix, something that the LU decomposition doesn't see.
Complex Full Pivoting LU Class Methods
CFullPivLU(cmat)
CFullPivLU(cmblock)
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CFPLU = Eigen.CFullPivLU
, cmat = new CM(3, 5).set([
1, 3, 0, 2, -1,
0, 0, 1, 4, -3,
1, 2, 1, 6, -4
])
, cfplu = new CFPLU(cmat)
, P = cfplu.permutationP()
, L = cfplu.matrixL()
, U = cfplu.matrixU()
, Q = cfplu.permutationQ();
console.log('%s', P.inverse().mula(L).mula(U).mula(Q.inverse()));
(1,0) (3,0) (0,0) (2,0) (-1,0)
(0,0) (2.22045e-16,0) (1,0) (4,0) (-3,0)
(1,0) (2,0) (1,0) (6,0) (-4,0)
Complex Full Pivoting LU Instance Methods
cfplu.permutationP()
Returns the permutation matrix P.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CFPLU = Eigen.CFullPivLU
, cmat = new CM(3, 5).set([
1, 3, 0, 2, -1,
0, 0, 1, 4, -3,
1, 2, 1, 6, -4
])
, cfplu = new CFPLU(cmat);
console.log('P = \n%s', cfplu.permutationP());
P =
(0,0) (0,0) (1,0)
(1,0) (0,0) (0,0)
(0,0) (1,0) (0,0)
cfplu.permutationQ()
Returns the permutation matrix Q.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CFPLU = Eigen.CFullPivLU
, cmat = new CM(3, 5).set([
1, 3, 0, 2, -1,
0, 0, 1, 4, -3,
1, 2, 1, 6, -4
])
, cfplu = new CFPLU(cmat);
console.log('Q = \n%s', cfplu.permutationQ());
Q =
(0,0) (0,0) (1,0) (0,0) (0,0)
(0,0) (1,0) (0,0) (0,0) (0,0)
(0,0) (0,0) (0,0) (1,0) (0,0)
(1,0) (0,0) (0,0) (0,0) (0,0)
(0,0) (0,0) (0,0) (0,0) (1,0)
cfplu.matrixL()
Returns the unit-lower-triangular matrix L.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CFPLU = Eigen.CFullPivLU
, cmat = new CM(3, 5).set([
1, 3, 0, 2, -1,
0, 0, 1, 4, -3,
1, 2, 1, 6, -4
])
, cfplu = new CFPLU(cmat);
console.log('L = \n%s', cfplu.matrixL());
L =
(1,0) (0,0) (0,0)
(0.333333,0) (1,0) (0,0)
(0.666667,0) (-0.571429,0) (1,0)
cfplu.matrixU()
Returns the upper-triangular matrix U.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CFPLU = Eigen.CFullPivLU
, cmat = new CM(3, 5).set([
1, 3, 0, 2, -1,
0, 0, 1, 4, -3,
1, 2, 1, 6, -4
])
, cfplu = new CFPLU(cmat);
console.log('U = \n%s', cfplu.matrixU());
U =
(6,0) (2,0) (1,0) (1,0) (-4,0)
(0,0) (2.33333,0) (0.666667,0) (-0.333333,0) (0.333333,0)
(0,0) (0,0) (-0.285714,0) (0.142857,0) (-0.142857,0)
cfplu.determinant()
Returns the determinant of the complex matrix of which *this is the LU decomposition. It has only linear complexity (that is, O(n) where n is the dimension of the complex square matrix) as the LU decomposition has already been computed.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CFPLU = Eigen.CFullPivLU
, cmat = CM.Random(3, 3)
, cfplu = new CFPLU(cmat)
, det = cfplu.determinant();
console.log('cmat = \n%s\n', cmat);
console.log('det = %s', det);
cmat =
(-0.93669,-0.95681) (-0.640516,0.839641) (-0.418346,0.860162)
(0.886216,0.637253) (-0.146449,0.632311) (0.73613,0.142591)
(0.306307,0.100039) (-0.741677,0.642565) (0.534108,0.757001)
det = (0.871298,0.0216014)
cfplu.inverse()
Returns the inverse of complex matrix of which *this is the LU decomposition.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CFPLU = Eigen.CFullPivLU
, cmat = CM.Random(3, 3)
, cfplu = new CFPLU(cmat)
, inv = cfplu.inverse();
console.log('%s', inv.isApprox(cmat.inverse()));
true
cfplu.isInvertible()
Returns true if the complex matrix of which *this is the LU decomposition is invertible.
var Eigen = require('eigenjs')
, CM = Eigen.Matrix
, CFPLU = Eigen.CFullPivLU
, cmat = new CM(3, 3).set([
1, 4, 5,
4, 2, 6,
5, 6, 3
])
, cfplu = new CFPLU(cmat);
console.log('%s', cfplu.isInvertible());
true
cfplu.solve(cmat)
cfplu.solve(cvec)
Returns a solution x to the equation Ax=b, where A is the complex matrix of which *this is the LU decomposition.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CV = Eigen.CVector
, CFPLU = Eigen.CFullPivLU
, cmat = new CM(3, 3).set([
0, 1, 1,
1, 2, 1,
2, 7, 9
])
, b = new CV([
4,
5,
6
])
, cfplu = new CFPLU(cmat);
console.log('x = \n%s', cfplu.solve(b));
x =
(-7,-0)
(8,0)
(-4,0)
cfplu.rank()
Returns the rank of the complex matrix of which *this is the LU decomposition.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CFPLU = Eigen.CFullPivLU
, cmat = new CM(3, 4).set([
2, 1, 0, 1,
0, 2, 1, 0,
2, 3, 1, 1
])
, cfplu = new CFPLU(cmat);
console.log('%d', cfplu.rank());
2
cfplu.dimensionOfKernel()
Returns the dimension of the kernel of the complex matrix of which *this is the LU decomposition.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CFPLU = Eigen.CFullPivLU
, cmat = CM(3, 4).set([
1, 1, 0, 2,
1, 2, 0, 3,
2, 3, 0, 5
])
, cfplu = new CFPLU(cmat)
, dim = cfplu.dimensionOfKernel();
console.log('dim = %d', dim);
dim = 2
cfplu.kernel()
Returns the kernel of the complex matrix, also called its null-space. The columns of the returned matrix will form a basis of the kernel.
var Eigen = require('eigenjs')
, CM = Eigen.CMatrix
, CFPLU = Eigen.CFullPivLU
, cmat = CM(3, 4).set([
1, 1, 0, 2,
1, 2, 0, 3,
2, 3, 0, 5
])
, cfplu = new CFPLU(cmat)
, ker = cfplu.kernel();
console.log('ker = \n%s', ker);
ker =
(1,0) (0,0)
(1,0) (-0,0)
(0,0) (1,0)
(-1,-0) (-0,-0)