bundles / scipy 1.17.1 / scipy / linalg / _basic / solve_circulant
function
scipy.linalg._basic:solve_circulant
source: /scipy/linalg/_basic.py :1148
Signature
def solve_circulant ( c , b , singular = raise , tol = None , caxis = -1 , baxis = 0 , outaxis = 0 ) Summary
Solve the equation C @ x = b for x, where C is a circulant matrix defined by c.
Extended Summary
C is the circulant matrix associated with the vector c.
The system is solved by doing division in Fourier space. The calculation is
x = ifft(fft(b) / fft(c))where fft and ifft are the fast Fourier transform and its inverse, respectively. For a large vector c, this is much faster than solving the system with the full circulant matrix.
Parameters
c: array_likeThe coefficients of the circulant matrix.
b: array_likeRight-hand side matrix in
a x = b.singular: str, optionalThis argument controls how a near singular circulant matrix is handled. If
singularis "raise" and the circulant matrix is near singular, aLinAlgErroris raised. Ifsingularis "lstsq", the least squares solution is returned. Default is "raise".tol: float, optionalIf any eigenvalue of the circulant matrix has an absolute value that is less than or equal to
tol, the matrix is considered to be near singular. If not given,tolis set totol = abs_eigs.max() * abs_eigs.size * np.finfo(np.float64).epswhere
abs_eigsis the array of absolute values of the eigenvalues of the circulant matrix.caxis: intWhen
chas dimension greater than 1, it is viewed as a collection of circulant vectors. In this case,caxisis the axis ofcthat holds the vectors of circulant coefficients.baxis: intWhen
bhas dimension greater than 1, it is viewed as a collection of vectors. In this case,baxisis the axis ofbthat holds the right-hand side vectors.outaxis: intWhen
corbare multidimensional, the value returned by solve_circulant is multidimensional. In this case,outaxisis the axis of the result that holds the solution vectors.
Returns
x: ndarraySolution to the system
C x = b.
Raises
: LinAlgErrorIf the circulant matrix associated with
cis near singular.
Notes
For a 1-D vector c with length m, and an array b with shape (m, ...),
solve_circulant(c, b)
returns the same result as
solve(circulant(c), b)
where solve and circulant are from scipy.linalg.
Examples
import numpy as np from scipy.linalg import solve_circulant, solve, circulant, lstsq✓
c = np.array([2, 2, 4]) b = np.array([1, 2, 3]) solve_circulant(c, b)✓
solve(circulant(c), b)
✓c = np.array([1, 1, 0, 0]) b = np.array([1, 2, 3, 4])✓
solve_circulant(c, b, singular='lstsq')
✗x, resid, rnk, s = lstsq(circulant(c), b)
✓x
✗c = np.array([[1.5, 2, 3, 0, 0], [1, 1, 4, 3, 2]]) b = np.arange(15).reshape(-1, 5)✓
x = solve_circulant(c[:, np.newaxis, :], b, baxis=-1, outaxis=-1) x.shape np.set_printoptions(precision=3) # For compact output of numbers.✓
x
✗solve_circulant(c[1], b[1, :])
✓See also
- circulant
circulant matrix
Aliases
-
scipy.linalg.solve_circulant