ndarray-lu-solve
solve a system of linear equations from an LU decomposition
example
var solve = ;var show = ;var crout = ;var ndarray = ;var zeros = ;var A =;var L = ;var U = ;;var X = ;var Y = ;var solution = ;console;console;
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 = ;var show = ;var crout = ;var ndarray = ;var zeros = ;var A =;var LU = ;;var solution = ;console;console;
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 =
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