bundles / scipy 1.17.1 / scipy / linalg / _basic / solve_banded
function
scipy.linalg._basic:solve_banded
source: /scipy/linalg/_basic.py :763
Signature
def solve_banded ( l_and_u , ab , b , overwrite_ab = False , overwrite_b = False , check_finite = True ) Summary
Solve the equation a @ x = b for x, where a is the banded matrix defined by ab.
Extended Summary
The matrix a is stored in ab using the matrix diagonal ordered form
ab[u + i - j, j] == a[i,j]Example of ab (shape of a is (6,6), u =1, l =2)
* a01 a12 a23 a34 a45 a00 a11 a22 a33 a44 a55 a10 a21 a32 a43 a54 * a20 a31 a42 a53 * *
The documentation is written assuming array arguments are of specified "core" shapes. However, array argument(s) of this function may have additional "batch" dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see linalg_batch for details.
Parameters
(l, u): (integer, integer)Number of non-zero lower and upper diagonals
ab: (`l` + `u` + 1, M) array_likeBanded matrix
b: (M,) or (M, K) array_likeRight-hand side
overwrite_ab: bool, optionalDiscard data in
ab(may enhance performance)overwrite_b: bool, optionalDiscard data in
b(may enhance performance)check_finite: bool, optionalWhether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.
Returns
x: (M,) or (M, K) ndarrayThe solution to the system a x = b. Returned shape depends on the shape of
b.
Examples
Solve the banded system a x = b, where:: [5 2 -1 0 0] [0] [1 4 2 -1 0] [1] a = [0 1 3 2 -1] b = [2] [0 0 1 2 2] [2] [0 0 0 1 1] [3] There is one nonzero diagonal below the main diagonal (l = 1), and two above (u = 2). The diagonal banded form of the matrix is:: [* * -1 -1 -1] ab = [* 2 2 2 2] [5 4 3 2 1] [1 1 1 1 *]import numpy as np from scipy.linalg import solve_banded ab = np.array([[0, 0, -1, -1, -1], [0, 2, 2, 2, 2], [5, 4, 3, 2, 1], [1, 1, 1, 1, 0]]) b = np.array([0, 1, 2, 2, 3]) x = solve_banded((1, 2), ab, b)✓
x
✗Aliases
-
scipy.linalg.solve_banded