solve#
- class saiunit.linalg.solve(a, b, **kwargs)#
Solve a linear system of equations.
SaiUnit implementation of
numpy.linalg.solve().This solves a (batched) linear system of equations
a @ x = bforxgivenaandb. The resulting unit isb.unit / a.unit.- Parameters:
a (
Array|ndarray|bool|number|bool|int|float|complex| saiunit.Quantity) – Coefficient matrix of shape(..., N, N).b (
Array|ndarray|bool|number|bool|int|float|complex| saiunit.Quantity) – Right-hand side of shape(N,)(for a 1-dimensional right-hand side) or(..., N, M)(for batched 2-dimensional right-hand side).
- Returns:
x – Solution array. The result has shape
(..., N)ifbis of shape(N,), and shape(..., N, M)otherwise. The resulting unit isb.unit / a.unit.- Return type:
Array|ndarray|bool|number|bool|int|float|complex| saiunit.Quantity
See also
saiunit.linalg.invCompute the inverse of a matrix.
saiunit.linalg.lstsqLeast-squares solution to a linear equation.
saiunit.linalg.tensorsolveSolve the tensor equation
a x = b.
Notes
Prefer
solveover explicitly computinginv(a) @ bfor better numerical precision and performance.Examples
>>> import saiunit as u >>> import jax.numpy as jnp >>> A = jnp.array([[1., 2., 3.], ... [2., 4., 2.], ... [3., 2., 1.]]) * u.meter >>> b = jnp.array([14., 16., 10.]) * u.second >>> x = u.linalg.solve(A, b) >>> x.unit Unit("s / m") >>> u.math.allclose(A @ x, b) Array(True, dtype=bool)