{ } Raw JSON

bundles / scipy latest / scipy / sparse / linalg / _special_sparse_arrays / Sakurai

class

scipy.sparse.linalg._special_sparse_arrays:Sakurai

source: /scipy/sparse/linalg/_special_sparse_arrays.py :521

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 : int

The size of the matrix.

dtype : dtype

Numerical 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.

eigenvalues

All 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)
Since all matrix entries are small integers, ``'int8'`` is the default dtype for storing matrix representations.
sak.toarray()
sak.tobanded()
sak.tosparse()
np.array_equal(sak.dot(np.eye(n)), sak.tosparse().toarray())
sak.eigenvalues()
sak.eigenvalues(2)
The banded form can be used in scipy functions for banded matrices, e.g.,
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