function linsolve
linsolve(): array | matrix

Solve a linear system of equations Ax = b.

Solves the linear system of equations Ax = b using LU factorization with row pivoting.

Examples

Solve a linear system with a vector

import { assertEquals } from "jsr:@std/assert";
import { eye } from "../../index.ts";

assertEquals(linsolve([[1, 1, -1], [1, -2, 3], [2, 3, 1]], [5, 6, 3]),
  [5.846153846153846, -2.3846153846153846, -1.5384615384615385]);

Solve a linear system with a matrix

import { assertEquals } from "jsr:@std/assert";
import { eye } from "../../index.ts";

assertEquals(linsolve([[1, 1, -1], [1, -2, 3], [2, 3, 1]], [[4], [-6], [7]]),
  [[1], [2], [-0.9999999999999999]]);

Solve a linear system with an identity matrix

import { assertEquals } from "jsr:@std/assert";
import { eye } from "../../index.ts";

assertEquals(linsolve([[1, 1, -1], [1, -2, 3], [2, 3, 1]], eye(3, 3)),
  [[0.846153846153846, 0.3076923076923077, -0.07692307692307707],
   [-0.3846153846153846, -0.23076923076923078, 0.30769230769230776],
   [-0.5384615384615384, 0.07692307692307691, 0.23076923076923078]]);

Parameters

A square matrix.

A vector or matrix.

Return Type

The solution to the linear system.

Throws

If not enough input arguments are provided.

If matrix dimensions do not agree.

If the matrix is not square.

If the matrix is singular.