pub struct SquareMatrix {
pub entries: Vec<f64>,
pub dim: usize,
}Expand description
A square matrix operator represented as a flat row-major array.
Fields§
§entries: Vec<f64>Row-major entries.
dim: usizeDimension (n x n).
Implementations§
Source§impl SquareMatrix
impl SquareMatrix
Sourcepub fn new(entries: Vec<f64>, dim: usize) -> Self
pub fn new(entries: Vec<f64>, dim: usize) -> Self
Create a new square matrix from row-major entries.
Panics if entries.len() != dim * dim.
Sourcepub fn add(&self, other: &SquareMatrix) -> SquareMatrix
pub fn add(&self, other: &SquareMatrix) -> SquareMatrix
Matrix addition.
Sourcepub fn sub(&self, other: &SquareMatrix) -> SquareMatrix
pub fn sub(&self, other: &SquareMatrix) -> SquareMatrix
Matrix subtraction.
Sourcepub fn scale(&self, s: f64) -> SquareMatrix
pub fn scale(&self, s: f64) -> SquareMatrix
Scalar multiplication.
Sourcepub fn mul(&self, other: &SquareMatrix) -> SquareMatrix
pub fn mul(&self, other: &SquareMatrix) -> SquareMatrix
Matrix multiplication.
Sourcepub fn pow(&self, k: u32) -> SquareMatrix
pub fn pow(&self, k: u32) -> SquareMatrix
Compute A^k (matrix exponentiation by repeated squaring).
Sourcepub fn operator_norm(&self) -> f64
pub fn operator_norm(&self) -> f64
The operator norm (approximated by the Frobenius norm).
Sourcepub fn frobenius_norm(&self) -> f64
pub fn frobenius_norm(&self) -> f64
The Frobenius norm: ||A||_F = sqrt(sum a_ij^2).
Sourcepub fn poly_eval(&self, poly: &Polynomial) -> SquareMatrix
pub fn poly_eval(&self, poly: &Polynomial) -> SquareMatrix
Evaluate a polynomial at a matrix: p(A) = c_0 I + c_1 A + c_2 A^2 + …
Uses Horner’s method for efficiency: p(A) = (… ((c_n A + c_{n-1}) A + c_{n-2}) A + …) + c_0.
Sourcepub fn spectral_radius(&self, max_iter: u32) -> f64
pub fn spectral_radius(&self, max_iter: u32) -> f64
Approximate spectral radius: r(A) = lim ||A^n||^{1/n}.
Computed by evaluating ||A^n||^{1/n} for increasing n and returning the
value at max_iter.
Sourcepub fn resolvent_2x2(&self, lambda: f64) -> Option<SquareMatrix>
pub fn resolvent_2x2(&self, lambda: f64) -> Option<SquareMatrix>
Compute the resolvent (lambda I - A)^{-1} for a 2x2 matrix using the explicit inverse formula.
Returns None if the matrix is not 2x2 or the determinant is zero
(i.e., lambda is in the spectrum).
Trait Implementations§
Source§impl Clone for SquareMatrix
impl Clone for SquareMatrix
Source§fn clone(&self) -> SquareMatrix
fn clone(&self) -> SquareMatrix
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more