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

ndarray-lu-solve

v1.1.0

Published

solve a linear system of equations from an LU decomposition

Downloads

28

Readme

ndarray-lu-solve

solve a system of linear equations from an LU decomposition

testling badge

build status

example

var solve = require('ndarray-lu-solve');
var show = require('ndarray-show');
var crout = require('ndarray-crout-decomposition');
var ndarray = require('ndarray');
var zeros = require('zeros');

var A = ndarray(
    [ 2, 1, -1, 8, -3, -1, 2, -11, -2, 1, 2, -3 ],
    [ 4, 3 ], [ 1, 4 ]
);
var L = zeros([ 3, 3 ]);
var U = zeros([ 3, 3 ]);
crout(A.hi(3,3), L, U);

var X = ndarray(new Float64Array(3));
var Y = ndarray(new Float64Array(3));
var solution = solve(L, U, A.lo(3,0).pick(0), X, Y);

console.log('input:\n' + show(A), '\n');
console.log('solution:\n' + show(solution));

output:

input:
   2.000    1.000   -1.000    8.000
  -3.000   -1.000    2.000  -11.000
  -2.000    1.000    2.000   -3.000 

solution:
   2.000    3.000   -1.000

You can pass fewer of the parameters if you want and use a packed representation for L and U in the same matrix:

var solve = require('ndarray-lu-solve');
var show = require('ndarray-show');
var crout = require('ndarray-crout-decomposition');
var ndarray = require('ndarray');
var zeros = require('zeros');

var A = ndarray(
    [ 2, 1, -1, 8, -3, -1, 2, -11, -2, 1, 2, -3 ],
    [ 4, 3 ], [ 1, 4 ]
);
var LU = zeros([ 3, 3 ]);
crout(A.hi(3,3), LU);

var solution = solve(LU, A.lo(3,0).pick(0));

console.log('input:\n' + show(A), '\n');
console.log('solution:\n' + show(solution));

output:

input:
   2.000    1.000   -1.000    8.000
  -3.000   -1.000    2.000  -11.000
  -2.000    1.000    2.000   -3.000 

solution:
   2.000    3.000   -1.000

Just note that it's up to you to ndscratch.free() the solution you get back to prevent leaking memory.

methods

var solve = require('ndarray-lu-solve')

var solution = solve(L, U, B, X, Y)

Given an L and U ndarrays from a decomposition and a vector B, solve the system LY = B for Y and UX = Y for X.

L and U can also be the same matrix.

The solution is written to X as the computation procedes but is also the return value.

Optional X and Y parameters are modified in-place and contain elements of the result. If not given, X and Y will be allocated.

var solution = solve(LU, B, X, Y)

You can omit the U parameter if you have a L and U values packed into the same matrix. The other parameters work the same.

install

With npm do:

npm install ndarray-lu-solve

license

MIT