node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org »

laplace-determinant

laplace-determinant

recursive determinant computation using Laplace expansion

Usage

Signature is (data [, scalar] [, order]) where:

  • data is an array which lenght must be a square.
  • scalar is an optional object used to compute determinant over any field (see below).
  • order defaults to Math.sqrt(data.lenght) and is used internally by recursion sub step.

All code in the examples below is intended to be contained into a single file

Basic usage is to compute determinant of matrices of common numbers.

var det = require('laplace-determinant')
 
// order = 1
 
det([10]) // 10
 
// order = 2
 
det([1, 0,
     0, 1]) // 1
 
det([1, 1,
     2, 1]) // -1
 
// order = 3
 
det([1, 0, 0,
     0, 1, 0,
     0, 0, 1]) // 1
 
det([0,  1, 0,
     2, -1, 0,
     0,  2, 1]) // -2
 
// order = 4
 
det([1, 0, 0, 0,
     0, 1, 0, 0,
     0, 0, 1, 0,
     0, 0, 0, 1]) // 1

The algorithm is recursive, so any order is allowed. If you want to benchmark it and compare this package with other implementations, you are welcome! Just contact me and I will happy to get this kind of useful feedback.

Optional scalar object defaults to common Real field, i.e.

scalar = {
  addition      : function (a, b) { return a + b },
  multiplication: function (a, b) { return a * b },
  negation      : function (a) { return -a }
}

It is possible to compute determinant over any field. Consider for example the Boolean algebra.

var boole = {
  addition      : function (a, b) { return a && b },
  multiplication: function (a, b) { return a || b },
  negation      : function (a) { return !a }
}
 
det([true, false,
     false, true], boole) // true