npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

na-gaussian-elimination

v1.0.0

Published

Solves systems of linear equations using Gaussian Elimination

Downloads

577

Readme

na-gaussian-elimination

npm version bower version build status

Solves a system of linear equations (matrix), using the Gaussian elimination algorithm.

Works in Node.js and the browser.

Example

Live Demo

// If not executing on node.js and want to listen to events,
// use an EventEmitter library, e.g., https://github.com/asyncly/EventEmitter2
GaussianElimination.setEventEmitter(EventEmitter2);

// Use bignumber.js to create numbers: https://github.com/MikeMcl/bignumber.js/
var zero = new BigNumber(0);
GaussianElimination.defaultOptions.zero = zero;

var gaussianElimination = new GaussianElimination();

var matrix = [
  [new BigNumber(1) , new BigNumber(2), new BigNumber(3)],
  [new BigNumber(4), new BigNumber(5), new BigNumber(6)],
  [new BigNumber(7), new BigNumber(8), new BigNumber(12)]
];
var result = [
  new BigNumber(4), new BigNumber(7), new BigNumber(10)
];

gaussianElimination.on('swapRows', function(ev) {
  console.log('swap rows ' + ev.i + ' and ' + ev.j);
});

var system = gaussianElimination.solve(matrix, result);

console.log('solution', system.solution); // [-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 and result must be objects with the following methods: minus, times, div, isZero, abs, comparedTo. This methods are all present in the bignumber.js library.
  • matrix and result are modified when solving the system.
  • It doesn't check the dimensions of matrix and result.

#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 of none, avoid zero, partial, scaled and complete. 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 when lu is falsy. Default: 0.