pub struct SymbolicMatrix { /* private fields */ }Expand description
A symbolic matrix where each element is an Expression.
This is useful for representing parameterized quantum gates, symbolic Hamiltonians, and other matrix expressions.
Implementations§
Source§impl SymbolicMatrix
impl SymbolicMatrix
Sourcepub fn new(elements: Vec<Vec<Expression>>) -> SymEngineResult<Self>
pub fn new(elements: Vec<Vec<Expression>>) -> SymEngineResult<Self>
Create a new symbolic matrix from a 2D array of expressions.
§Errors
Returns error if the input is empty
Sourcepub fn from_flat(
elements: Vec<Expression>,
rows: usize,
cols: usize,
) -> SymEngineResult<Self>
pub fn from_flat( elements: Vec<Expression>, rows: usize, cols: usize, ) -> SymEngineResult<Self>
Create a matrix from a flat vector with specified dimensions.
§Errors
Returns error if the dimensions don’t match the vector length
Sourcepub fn diagonal(diag: Vec<Expression>) -> Self
pub fn diagonal(diag: Vec<Expression>) -> Self
Create a diagonal matrix from a vector of diagonal elements.
Sourcepub fn from_array(arr: &Array2<f64>) -> Self
pub fn from_array(arr: &Array2<f64>) -> Self
Create a matrix from a numeric Array2.
Sourcepub fn from_complex_array(arr: &Array2<Complex64>) -> Self
pub fn from_complex_array(arr: &Array2<Complex64>) -> Self
Create a matrix from a complex Array2.
Sourcepub fn get(&self, i: usize, j: usize) -> &Expression
pub fn get(&self, i: usize, j: usize) -> &Expression
Sourcepub fn get_mut(&mut self, i: usize, j: usize) -> &mut Expression
pub fn get_mut(&mut self, i: usize, j: usize) -> &mut Expression
Sourcepub fn set(&mut self, i: usize, j: usize, value: Expression)
pub fn set(&mut self, i: usize, j: usize, value: Expression)
Sourcepub fn row(&self, i: usize) -> Vec<Expression>
pub fn row(&self, i: usize) -> Vec<Expression>
Get a row as a vector of expressions.
Sourcepub fn col(&self, j: usize) -> Vec<Expression>
pub fn col(&self, j: usize) -> Vec<Expression>
Get a column as a vector of expressions.
Sourcepub fn add(&self, other: &Self) -> SymEngineResult<Self>
pub fn add(&self, other: &Self) -> SymEngineResult<Self>
Sourcepub fn sub(&self, other: &Self) -> SymEngineResult<Self>
pub fn sub(&self, other: &Self) -> SymEngineResult<Self>
Sourcepub fn matmul(&self, other: &Self) -> SymEngineResult<Self>
pub fn matmul(&self, other: &Self) -> SymEngineResult<Self>
Sourcepub fn scale(&self, scalar: &Expression) -> Self
pub fn scale(&self, scalar: &Expression) -> Self
Scalar multiplication.
Sourcepub fn trace(&self) -> SymEngineResult<Expression>
pub fn trace(&self) -> SymEngineResult<Expression>
Sourcepub fn commutator(&self, other: &Self) -> SymEngineResult<Self>
pub fn commutator(&self, other: &Self) -> SymEngineResult<Self>
Commutator [A, B] = AB - BA.
§Errors
Returns error if dimensions don’t match or matrices are not square.
Sourcepub fn anticommutator(&self, other: &Self) -> SymEngineResult<Self>
pub fn anticommutator(&self, other: &Self) -> SymEngineResult<Self>
Sourcepub fn eval(
&self,
values: &HashMap<String, f64>,
) -> SymEngineResult<Array2<f64>>
pub fn eval( &self, values: &HashMap<String, f64>, ) -> SymEngineResult<Array2<f64>>
Evaluate all matrix elements with given variable values.
§Errors
Returns error if any element evaluation fails.
Sourcepub fn substitute(&self, var: &Expression, value: &Expression) -> Self
pub fn substitute(&self, var: &Expression, value: &Expression) -> Self
Substitute a variable with an expression in all elements.
Sourcepub fn diff(&self, var: &Expression) -> Self
pub fn diff(&self, var: &Expression) -> Self
Compute the derivative of all elements with respect to a variable.
Trait Implementations§
Source§impl Clone for SymbolicMatrix
impl Clone for SymbolicMatrix
Source§fn clone(&self) -> SymbolicMatrix
fn clone(&self) -> SymbolicMatrix
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SymbolicMatrix
impl Debug for SymbolicMatrix
Source§impl Display for SymbolicMatrix
impl Display for SymbolicMatrix
Auto Trait Implementations§
impl Freeze for SymbolicMatrix
impl RefUnwindSafe for SymbolicMatrix
impl Send for SymbolicMatrix
impl Sync for SymbolicMatrix
impl Unpin for SymbolicMatrix
impl UnwindSafe for SymbolicMatrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more