Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
330 changes: 330 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dgtsv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# dgtsv

> Solve a system of linear equations `A * X = B`, where `A` is an `N`-by-`N` tridiagonal matrix, using Gaussian elimination with partial pivoting.

<section class="intro">

The `dgtsv` routine solves a real system of linear equations

<!-- <equation class="equation" label="eq:tridiagonal_system" align="center" raw="A X = B" alt="System of linear equations."> -->

```math
A X = B
```

<!-- </equation> -->

where `A` is an `N`-by-`N` tridiagonal matrix, by Gaussian elimination with partial pivoting. Here, `B` and the solution `X` are `N`-by-`NRHS` matrices.

For a 5-by-5 tridiagonal matrix `A`, elements are stored in three arrays:

<!-- <equation class="equation" label="eq:matrix_a" align="center" raw="A = \left[\begin{array}{rrrrr}d_1 & du_1 & 0 & 0 & 0 \\dl_1 & d_2 & du_2 & 0 & 0 \\0 & dl_2 & d_3 & du_3 & 0 \\0 & 0 & dl_3 & d_4 & du_4 \\0 & 0 & 0 & dl_4 & d_5\end{array}\right]" alt="Representation of matrix A."> -->

```math
A = \left[
\begin{array}{rrrrr}
d_1 & du_1 & 0 & 0 & 0 \\
dl_1 & d_2 & du_2 & 0 & 0 \\
0 & dl_2 & d_3 & du_3 & 0 \\
0 & 0 & dl_3 & d_4 & du_4 \\
0 & 0 & 0 & dl_4 & d_5
\end{array}
\right]
```

<!-- </equation> -->

where:

- `dl` contains the subdiagonal elements.
- `d` contains the diagonal elements.
- `du` contains the superdiagonal elements.

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var dgtsv = require( '@stdlib/lapack/base/dgtsv' );
```

#### dgtsv( order, N, NRHS, DL, D, DU, B, LDB )

Solves a system of linear equations `A * X = B`, where `A` is an `N`-by-`N` tridiagonal matrix, using Gaussian elimination with partial pivoting.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var DL = new Float64Array( [ 1.0, 1.0 ] );
var D = new Float64Array( [ 2.0, 3.0, 1.0 ] );
var DU = new Float64Array( [ 1.0, 1.0 ] );
var B = new Float64Array( [ 4.0, 10.0, 5.0 ] );

/*
A = [
[ 2.0, 1.0, 0.0 ],
[ 1.0, 3.0, 1.0 ],
[ 0.0, 1.0, 1.0 ]
]
*/

dgtsv( 'column-major', 3, 1, DL, D, DU, B, 3 );
// B => <Float64Array>[ 1.0, 2.0, 3.0 ]
```

The function has the following parameters:

- **order**: storage layout of `B`.
- **N**: number of rows/columns in `A`.
- **NRHS**: number of right-hand sides (i.e., the number of columns in `B`).
- **DL**: the first sub-diagonal of `A` as a [`Float64Array`][mdn-float64array]. Should have `N-1` indexed elements. `DL` is overwritten by the `(N-2)` elements of the second super-diagonal of the upper triangular matrix `U` from the `LU` factorization of `A`.
- **D**: the diagonal of `A` as a [`Float64Array`][mdn-float64array]. Should have `N` indexed elements. `D` is overwritten by the `N` diagonal elements of `U`.
- **DU**: the first super-diagonal of `A` as a [`Float64Array`][mdn-float64array]. Should have `N-1` indexed elements. `DU` is overwritten by the `(N-1)` elements of the first super-diagonal of `U`.
- **B**: input matrix `B` having `N` rows and `NRHS` columns as a [`Float64Array`][mdn-float64array]. On exit, `B` is overwritten by the solution matrix `X`.
- **LDB**: stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`).

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

<!-- eslint-disable stdlib/capitalized-comments -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );

// Initial arrays...
var DL0 = new Float64Array( [ 0.0, 1.0, 1.0 ] );
var D0 = new Float64Array( [ 0.0, 2.0, 3.0, 1.0 ] );
var DU0 = new Float64Array( [ 0.0, 1.0, 1.0 ] );
var B0 = new Float64Array( [ 0.0, 4.0, 10.0, 5.0 ] );

// Create offset views...
var DL = new Float64Array( DL0.buffer, DL0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var D = new Float64Array( D0.buffer, D0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var DU = new Float64Array( DU0.buffer, DU0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var B = new Float64Array( B0.buffer, B0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dgtsv( 'column-major', 3, 1, DL, D, DU, B, 3 );
// B0 => <Float64Array>[ 0.0, 1.0, 2.0, 3.0 ]
```

<!-- lint disable maximum-heading-length -->

#### dgtsv.ndarray( N, NRHS, DL, sdl, odl, D, sd, od, DU, sdu, odu, B, sb1, sb2, ob )

Solves a system of linear equations `A * X = B`, where `A` is an `N`-by-`N` tridiagonal matrix, using Gaussian elimination with partial pivoting and alternative indexing semantics.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var DL = new Float64Array( [ 1.0, 1.0 ] );
var D = new Float64Array( [ 2.0, 3.0, 1.0 ] );
var DU = new Float64Array( [ 1.0, 1.0 ] );
var B = new Float64Array( [ 4.0, 10.0, 5.0 ] );

dgtsv.ndarray( 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, B, 1, 3, 0 );
// B => <Float64Array>[ 1.0, 2.0, 3.0 ]
```

The function has the following additional parameters:

- **sdl**: stride length for `DL`.
- **odl**: starting index for `DL`.
- **sd**: stride length for `D`.
- **od**: starting index for `D`.
- **sdu**: stride length for `DU`.
- **odu**: starting index for `DU`.
- **sb1**: stride of the first dimension of `B`.
- **sb2**: stride of the second dimension of `B`.
- **ob**: starting index for `B`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example,

<!-- eslint-disable max-len -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var DL = new Float64Array( [ 0.0, 1.0, 1.0 ] );
var D = new Float64Array( [ 0.0, 2.0, 3.0, 1.0 ] );
var DU = new Float64Array( [ 0.0, 1.0, 1.0 ] );
var B = new Float64Array( [ 0.0, 4.0, 10.0, 5.0 ] );

dgtsv.ndarray( 3, 1, DL, 1, 1, D, 1, 1, DU, 1, 1, B, 1, 3, 1 );
// B => <Float64Array>[ 0.0, 1.0, 2.0, 3.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Both functions mutate the input arrays `DL`, `D`, `DU`, and `B`. On exit, `B` is overwritten by the solution matrix `X`.

- Both functions return a status code indicating success or failure. The status code indicates the following conditions:

- `0`: the solution was successfully computed.
- `>0`: `U(k, k)` is exactly zero, where `k` equals the status code value. The factorization has been completed, but the factor `U` is exactly singular, and the solution could not be computed.

- `dgtsv()` corresponds to the [LAPACK][LAPACK] routine [`dgtsv`][lapack-dgtsv].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var dgtsv = require( '@stdlib/lapack/base/dgtsv' );

var N = 5;

var DL = new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] );
var D = new Float64Array( [ 4.0, 4.0, 4.0, 4.0, 4.0 ] );
var DU = new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] );
var B = new Float64Array( [ 5.0, 6.0, 6.0, 6.0, 5.0 ] );

/*
A = [
[ 4.0, 1.0, 0.0, 0.0, 0.0 ],
[ 1.0, 4.0, 1.0, 0.0, 0.0 ],
[ 0.0, 1.0, 4.0, 1.0, 0.0 ],
[ 0.0, 0.0, 1.0, 4.0, 1.0 ],
[ 0.0, 0.0, 0.0, 1.0, 4.0 ]
]
*/

// Solve `A*X = B` for `X`:
var info = dgtsv( 'column-major', N, 1, DL, D, DU, B, N );

console.log( B );
console.log( info );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
TODO
```

#### TODO

TODO.

```c
TODO
```

TODO

```c
TODO
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
TODO
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[lapack]: https://www.netlib.org/lapack/explore-html/

[lapack-dgtsv]: https://www.netlib.org/lapack/explore-html/d6/ddb/group__gtsv_ga6b06a11b8e2dced10bc9cd3c20a09484.html#ga6b06a11b8e2dced10bc9cd3c20a09484

[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

</section>

<!-- /.links -->
Loading