imsl.linalg.lu_solve

lu_solve(a, b, transpose=False)

Solve a general system Ax = b of linear equations.

Parameters:
  • a ((N,N) array_like) – Array containing the matrix A.
  • b ((N,) array_like) – Array containing the right-hand side. Elements of this array must be convertible to the same type as array a.
  • transpose (bool, optional) – If True, solve \(A^Tx = b\) (if a contains entries of type float) or \(A^Hx = b\) (if a contains entries of type complex). Default is False.
Returns:

The solution x of the linear system Ax=b.

Return type:

*(N,) ndarray*

Notes

In a first step, this function computes the LU factorization of matrix A. Then, it finds the solution of the linear system Ax = b by solving two simpler systems, \(y=L^{-1}b\) and \(x=U^{-1}y\).

This function creates a temporary LU() instance and calls method LU.solve() on that instance.

Examples

>>> import imsl.linalg as la
>>> a = [[1.0, 3.0, 3.0], [1.0, 3.0, 4.0], [1.0, 4.0, 3.0]]
>>> b = [1.0, 4.0, -1.0]
>>> x = la.lu_solve(a, b)
>>> print(x) 
[-2. -2. 3.]