scipy.sparse.linalg.

spsolve#

scipy.sparse.linalg.spsolve(A, b, permc_spec=None, use_umfpack=True)[原始碼]#

解稀疏線性系統 Ax=b,其中 b 可以是向量或矩陣。

參數:
Andarray 或稀疏陣列或矩陣

方陣 A 將會被轉換成 CSC 或 CSR 格式

bndarray 或稀疏陣列或矩陣

表示方程式右側的矩陣或向量。如果是向量,b.shape 必須是 (n,) 或 (n, 1)。

permc_specstr,可選

如何排列矩陣的列以保留稀疏性。(預設值:'COLAMD')

  • NATURAL:自然排序。

  • MMD_ATA:A^T A 結構上的最小度排序。

  • MMD_AT_PLUS_A:A^T+A 結構上的最小度排序。

  • COLAMD:近似最小度列排序 [1], [2]

use_umfpackbool,可選

如果為 True(預設值),則使用 UMFPACK 求解方案 [3], [4], [5], [6] 。只有當 b 是向量且安裝了 scikits.umfpack 時才會參考此項。

返回:
xndarray 或稀疏陣列或矩陣

稀疏線性方程式的解。如果 b 是向量,則 x 是大小為 A.shape[1] 的向量。如果 b 是矩陣,則 x 是大小為 (A.shape[1], b.shape[1]) 的矩陣

註解

對於求解矩陣表達式 AX = B,此求解器假設結果矩陣 X 是稀疏的,這在非常稀疏的輸入中通常是如此。如果結果 X 是密集的,則建構此稀疏結果將相對昂貴。在這種情況下,請考慮將 A 轉換為密集矩陣並使用 scipy.linalg.solve 或其變體。

參考文獻

[1]

T. A. Davis, J. R. Gilbert, S. Larimore, E. Ng, Algorithm 836: COLAMD, an approximate column minimum degree ordering algorithm, ACM Trans. on Mathematical Software, 30(3), 2004, pp. 377–380. DOI:10.1145/1024074.1024080

[2]

T. A. Davis, J. R. Gilbert, S. Larimore, E. Ng, A column approximate minimum degree ordering algorithm, ACM Trans. on Mathematical Software, 30(3), 2004, pp. 353–376. DOI:10.1145/1024074.1024079

[3]

T. A. Davis, Algorithm 832: UMFPACK - an unsymmetric-pattern multifrontal method with a column pre-ordering strategy, ACM Trans. on Mathematical Software, 30(2), 2004, pp. 196–199. https://dl.acm.org/doi/abs/10.1145/992200.992206

[4]

T. A. Davis, A column pre-ordering strategy for the unsymmetric-pattern multifrontal method, ACM Trans. on Mathematical Software, 30(2), 2004, pp. 165–195. https://dl.acm.org/doi/abs/10.1145/992200.992205

[5]

T. A. Davis and I. S. Duff, A combined unifrontal/multifrontal method for unsymmetric sparse matrices, ACM Trans. on Mathematical Software, 25(1), 1999, pp. 1–19. https://doi.org/10.1145/305658.287640

[6]

T. A. Davis and I. S. Duff, An unsymmetric-pattern multifrontal method for sparse LU factorization, SIAM J. Matrix Analysis and Computations, 18(1), 1997, pp. 140–158. https://doi.org/10.1137/S0895479894246905T.

範例

>>> import numpy as np
>>> from scipy.sparse import csc_array
>>> from scipy.sparse.linalg import spsolve
>>> A = csc_array([[3, 2, 0], [1, -1, 0], [0, 5, 1]], dtype=float)
>>> B = csc_array([[2, 0], [-1, 0], [2, 0]], dtype=float)
>>> x = spsolve(A, B)
>>> np.allclose(A.dot(x).toarray(), B.toarray())
True