Best Option To Solve A Banded Matrix

Best option to solve a banded matrix

Solve the equation a x = b for x, assuming a is banded matrix.

The matrix a is stored in ab using the matrix diagonal ordered form:

Example of ab (shape of a is (6,6), u =1, l =2):

Parameters
(l, u)(integer, integer)

Number of non-zero lower and upper diagonals

ab(l + u + 1, M) array_like

Banded matrix

b(M,) or (M, K) array_like

Right-hand side

overwrite_abbool, optional

Discard data in ab (may enhance performance)

overwrite_bbool, optional

Discard data in b (may enhance performance)

check_finitebool, optional

Whether to check that the input matrices contain only finite numbers.

Exploring the solution set of Ax = b - Matrix transformations - Linear Algebra - Khan Academy

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) ndarray

The solution to the system a x = b.

Returned shape depends on the shape of b.

Examples

Solve the banded system a x = b, where:

There is one nonzero diagonal below the main diagonal (l = 1), and two above (u = 2). The diagonal banded form of the matrix is:

ab[u+i-j,j]==a[i,j]
*a01a12a23a34a45a00a11a22a33a44a55a10a21a32a43a54*a20a31a42a53**
[52-100][0][142-10][1]a=[0132-1]b=[2][00122][2][00011][3]
[**-1-1-1]ab=[*2222][54321][1111*]
>>> fromscipy.linalgimportsolve_banded>>> ab=np.array([[0,0,-1,-1,-1],...

Best option to solve a banded matrix

[0,2,2,2,2],... [5,4,3,2,1],...

Best option to solve a banded matrix

[1,1,1,1,0]])>>> b=np.array([0,1,2,2,3])>>> x=solve_banded((1,2),ab,b)>>> xarray([-2.37288136, 3.93220339, -4. , 4.3559322 , -1.3559322 ])

Best option to solve a banded matrix