Solving Linear Systems

Solve $Ax = b$.

Direct Methods

1import numpy as np
2from scipy.linalg import solve, lu
3
4# Direct solve
5x = np.linalg.solve(A, b)
6
7# LU decomposition
8P, L, U = lu(A)

Iterative Methods

1from scipy.sparse.linalg import cg, gmres
2
3# Conjugate gradient (for symmetric positive definite)
4x, info = cg(A, b)
5
6# GMRES (general)
7x, info = gmres(A, b)

Further Reading

Related Snippets