๐ข A simple linear solver for real and complex numbers in WebAssembly.
- Node.js >= 14.17
Clone this repository, and then run the command bellow in the repository folder:
wasm-pack build --target web
This command will build the binaries and the JavaScript files on ./pkg/
.
wasm-pack test --node
You can find an exemple of usage in ./example/
.
The matrices are defined as below:
//| 1.0 0.0 |
//| 0.0 1.0 |
const eye2x2 = {
nrow: 2,
ncol: 2,
elements: [
{
row: 0,
col: 0,
// If the element is real:
value: 1.0,
// If the element is complex (a + jb):
// value: (a, b),
},
{
row: 1,
col: 1,
// If the element is real:
value: 1.0,
// If the element is complex (a + jb):
// value: (a, b),
}
]
}
Vectors are defined as a Matrix with ncols: 1
.
NOTE: You only need to define non-zero values.
NOTE: If some of the matrix's element is complex, all elements must be defined as complex.
Lets defining A
a nxn matrix b
a vector nx1. The linear system is defined by Ax = b
.
After build the Axb
, we can solve this linear system as below:
import init, { solve, complex_solve } from 'path/to/axb.js';
async () -> {
const A = //...
const b = //...
await init();
const x = solve(A, b); // For real elements
// const x = complex_solve(A, b); // For complex elements
}()
The returns of these functions are Matrices as well.
NOTE:
A
andb
must have the same type of elements (real or complex).
Axb is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE_APACHE and LICENSE_MITfor details.