bundles / scipy 1.17.1 / scipy / sparse / linalg / _special_sparse_arrays / Sakurai
class
scipy.sparse.linalg._special_sparse_arrays:Sakurai
Signature
class Sakurai ( n , dtype = <class 'numpy.int8'> ) Members
Summary
Construct a Sakurai matrix in various formats and its eigenvalues.
Extended Summary
Constructs the "Sakurai" matrix motivated by reference [1]: square real symmetric positive definite and 5-diagonal with the main diagonal [5, 6, 6, ..., 6, 6, 5], the ``+1 and -1 diagonals filled with -4, and the +2 and -2 diagonals made of 1. Its eigenvalues are analytically known to be 16. * np.power(np.cos(0.5 * k * np.pi / (n + 1)), 4). The matrix gets ill-conditioned with its size growing. It is useful for testing and benchmarking sparse eigenvalue solvers especially those taking advantage of its banded 5-diagonal structure. See the notes below for details.
Parameters
n: intThe size of the matrix.
dtype: dtypeNumerical type of the array. Default is
np.int8.
Methods
toarray()Construct a dense array from Laplacian data
tosparse()Construct a sparse array from Laplacian data
tobanded()The Sakurai matrix in the format for banded symmetric matrices, i.e., (3, n) ndarray with 3 upper diagonals placing the main diagonal at the bottom.
eigenvaluesAll eigenvalues of the Sakurai matrix ordered ascending.
Notes
Reference [1] introduces a generalized eigenproblem for the matrix pair A and B where A is the identity so we turn it into an eigenproblem just for the matrix B that this function outputs in various formats together with its eigenvalues.
Examples
import numpy as np from scipy.sparse.linalg._special_sparse_arrays import Sakurai from scipy.linalg import eig_banded n = 6 sak = Sakurai(n)✓
sak.toarray() sak.tobanded()✓
sak.tosparse()
✗np.array_equal(sak.dot(np.eye(n)), sak.tosparse().toarray())
✓sak.eigenvalues() sak.eigenvalues(2)✗
e = eig_banded(sak.tobanded(), eigvals_only=True) np.allclose(sak.eigenvalues(), e, atol= n * n * n * np.finfo(float).eps)✓
Aliases
-
scipy.sparse.linalg._special_sparse_arrays.Sakurai