spsolve#
- scipy.sparse.linalg.spsolve(A, b, permc_spec=None, use_umfpack=True)[原始碼]#
解稀疏線性系統 Ax=b,其中 b 可以是向量或矩陣。
- 參數:
- 返回:
- 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