Skip to main content

ComplexMatrix

Struct ComplexMatrix 

Source
pub struct ComplexMatrix {
    pub data: Vec<Complex>,
    pub rows: usize,
    pub cols: usize,
}
Expand description

Complex matrix with row-major storage.

Fields§

§data: Vec<Complex>§rows: usize§cols: usize

Implementations§

Source§

impl ComplexMatrix

Source

pub fn new(rows: usize, cols: usize) -> Self

Create a new complex matrix.

Source

pub fn from_data(data: Vec<Complex>, rows: usize, cols: usize) -> Self

Create matrix from data.

Source

pub fn get(&self, row: usize, col: usize) -> Complex

Get element at (row, col).

Source

pub fn set(&mut self, row: usize, col: usize, value: Complex)

Set element at (row, col).

Source

pub fn zeros(rows: usize, cols: usize) -> Self

Create zero matrix.

Source

pub fn identity(n: usize) -> Self

Create identity matrix.

Source

pub fn add(&self, other: &ComplexMatrix) -> ComplexMatrix

Matrix addition.

Source

pub fn sub(&self, other: &ComplexMatrix) -> ComplexMatrix

Matrix subtraction.

Source

pub fn scale(&self, scalar: Complex) -> ComplexMatrix

Scalar multiplication.

Source

pub fn mul(&self, other: &ComplexMatrix) -> ComplexMatrix

Matrix multiplication.

Source

pub fn transpose(&self) -> ComplexMatrix

Matrix transpose.

Source

pub fn hermitian(&self) -> ComplexMatrix

Conjugate transpose (Hermitian transpose).

Source

pub fn trace(&self) -> Complex

Matrix trace.

Source

pub fn determinant(&self) -> Complex

Matrix determinant (for small matrices).

Source

pub fn lu_decomposition( &self, ) -> Option<(ComplexMatrix, ComplexMatrix, Vec<usize>)>

LU decomposition with partial pivoting.

Source

pub fn solve(&self, b: &[Complex]) -> Option<Vec<Complex>>

Solve linear system Ax = b using LU decomposition.

Source

pub fn inverse(&self) -> Option<ComplexMatrix>

Matrix inverse.

Source

pub fn is_hermitian(&self, tolerance: f64) -> bool

Check if matrix is Hermitian (equal to its conjugate transpose).

Source

pub fn is_unitary(&self, tolerance: f64) -> bool

Check if matrix is unitary (A * A^H = I).

Source

pub fn frobenius_norm(&self) -> f64

Frobenius norm.

Source

pub fn power(&self, n: usize) -> ComplexMatrix

Matrix power A^n.

Source

pub fn exp(&self, iterations: usize) -> ComplexMatrix

Matrix exponential e^A using Taylor series with scaling-and-squaring: compute e^(A/2^k) then square k times.

Source

pub fn ln(&self, iterations: usize) -> Option<ComplexMatrix>

Matrix logarithm ln(A) using Taylor series around identity. Returns None if the series cannot converge, i.e. if any eigenvalue of A is outside the disk |λ - 1| < 1 (checked via a Frobenius-norm bound on A - I, which is conservative but safe).

Trait Implementations§

Source§

impl Clone for ComplexMatrix

Source§

fn clone(&self) -> ComplexMatrix

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ComplexMatrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.