na-gaussian-elimination
Solves a system of linear equations, using the Gaussian elimination algorithm.
Works in Node.js and the browser.
Example
// If not executing on node.js and want to listen to events,// use an EventEmitter library, e.g., https://github.com/asyncly/EventEmitter2GaussianElimination; // Use bignumber.js to create numbers: https://github.com/MikeMcl/bignumber.js/var zero = 0;GaussianEliminationdefaultOptionszero = zero; var gaussianElimination = ; var matrix = 1 2 3 4 5 6 7 8 12;var result = 4 7 10; gaussianElimination; var system = gaussianElimination; console; // [-2, 3, 0]
Functions and properties of GaussianElimination
.setEventEmitter(EventEmitter)
If you want to use the events in the browser, you must set an EventEmitter library
using the GaussianElimination.setEventEmitter(EventEmitter)
method.
.defaultOptions
Used when no other option is specified in the constructor. See Options section.
.SolutionError
Error emitted (or thrown) when there is an error while solving the system.
.OptionsError
Error thrown in the constructor when an option has an invalid value.
#solve(matrix, result)
Solves the system and returns an object with the solution
property.
matrix
can be rectangular.- The values of
matrix
andresult
must be objects with the following methods:minus
,times
,div
,isZero
,abs
,comparedTo
. This methods are all present in the bignumber.js library. matrix
andresult
are modified when solving the system.- It doesn't check the dimensions of
matrix
andresult
.
#forwardElimination(matrix, result)
Reduces the given system to row echelon form (without the condition that the leading coefficient must be 1).
#backSubstitution(matrix, result)
Finds a solution for the system.
Options
pivoting
: one ofnone
,avoid zero
,partial
,scaled
andcomplete
. Default:'partial'
.lu
: if it is truthy, then the matrix is transformed into an LU matrix. If not, then the lower triangle of the matrix is filled with zeroes. Default:false
.zero
: the value used to represent a zero. Only used whenlu
is falsy. Default:0
.