2022-03-01 13:04:09 +01:00

64 lines
2.1 KiB
Markdown

---
layout: default
---
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
<h1 id="function-lusolve">Function lusolve <a href="#function-lusolve" title="Permalink">#</a></h1>
Solves the linear system `A * x = b` where `A` is an [n x n] matrix and `b` is a [n] column vector.
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
math.lusolve(A, b) // returns column vector with the solution to the linear system A * x = b
math.lusolve(lup, b) // returns column vector with the solution to the linear system A * x = b, lup = math.lup(A)
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`A` | Matrix &#124; Array &#124; Object | Invertible Matrix or the Matrix LU decomposition
`b` | Matrix &#124; Array | Column Vector
`order` | number | The Symbolic Ordering and Analysis order, see slu for details. Matrix must be a SparseMatrix
`threshold` | Number | Partial pivoting threshold (1 for partial pivoting), see slu for details. Matrix must be a SparseMatrix.
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
DenseMatrix &#124; Array | Column vector with the solution to the linear system A * x = b
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
Type | Description
---- | -----------
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
```js
const m = [[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]
const x = math.lusolve(m, [-1, -1, -1, -1]) // x = [[-1], [-0.5], [-1/3], [-0.25]]
const f = math.lup(m)
const x1 = math.lusolve(f, [-1, -1, -1, -1]) // x1 = [[-1], [-0.5], [-1/3], [-0.25]]
const x2 = math.lusolve(f, [1, 2, 1, -1]) // x2 = [[1], [1], [1/3], [-0.25]]
const a = [[-2, 3], [2, 1]]
const b = [11, 9]
const x = math.lusolve(a, b) // [[2], [5]]
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[lup](lup.html),
[slu](slu.html),
[lsolve](lsolve.html),
[usolve](usolve.html)