Skip to content
Symi Docs
Rust

The Rust manual covers the recommended facade. The complete native crate is documented in the native Rust API reference.

On this page

Vector calculus

Coordinates are passed as a list of variable names; vector fields as a list of component expressions in the same order. Empty variable lists and component/variable count mismatches raise.

gradient#

api::analysis::Session method

pub fn gradient<'a, IteratorType, VariableType>(
    &self,
    scalar_field: &Expression,
    variables: IteratorType,
) -> Result<Vec<Expression>, ApiError>
where
    IteratorType: IntoIterator<Item = VariableType>,
    VariableType: Into<VariableLike<'a>>,

∇f\nabla f: the partial derivatives in the order of variables.

divergence#

api::analysis::Session method

pub fn divergence<'a, IteratorType, VariableType>(
    &self,
    vector_components: &[Expression],
    variables: IteratorType,
) -> Result<Expression, ApiError>
where
    IteratorType: IntoIterator<Item = VariableType>,
    VariableType: Into<VariableLike<'a>>,

∇⋅F=∑i∂Fi/∂xi\nabla\cdot F = \sum_i \partial F_i/\partial x_i; component and variable counts must match.

curl#

api::analysis::Session method

pub fn curl<'a, IteratorType, VariableType>(
    &self,
    vector_components: &[Expression],
    variables: IteratorType,
) -> Result<Vec<Expression>, ApiError>
where
    IteratorType: IntoIterator<Item = VariableType>,
    VariableType: Into<VariableLike<'a>>,

∇×F\nabla\times F. Requires exactly three components and three variables; other dimensions raise.

laplacian#

api::analysis::Session method

pub fn laplacian<'a, IteratorType, VariableType>(
    &self,
    scalar_field: &Expression,
    variables: IteratorType,
) -> Result<Expression, ApiError>
where
    IteratorType: IntoIterator<Item = VariableType>,
    VariableType: Into<VariableLike<'a>>,

Δf=∇⋅∇f\Delta f = \nabla\cdot\nabla f.

jacobian#

api::analysis::Session method

pub fn jacobian<'a, IteratorType, VariableType>(
    &self,
    vector_components: &[Expression],
    variables: IteratorType,
) -> Result<Matrix, ApiError>
where
    IteratorType: IntoIterator<Item = VariableType>,
    VariableType: Into<VariableLike<'a>>,

The matrix with entry (i,j)=∂Fi/∂xj(i, j) = \partial F_i/\partial x_j (rows index components, columns index variables). Returned as a Matrix so the result composes with the matrix methods.

hessian#

api::analysis::Session method

pub fn hessian<'a, IteratorType, VariableType>(
    &self,
    scalar_field: &Expression,
    variables: IteratorType,
) -> Result<Matrix, ApiError>
where
    IteratorType: IntoIterator<Item = VariableType>,
    VariableType: Into<VariableLike<'a>>,

The n×nn\times n matrix of second partials, computed as the Jacobian of the gradient; structurally symmetric on smooth input.

Example#

Differential operators over an ordered coordinate list.

Rust
use symi::api::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let session = Session::new();
    let x = session.symbol("x");
    let y = session.symbol("y");
    let z = session.symbol("z");

    for component in session.gradient(&session.parse("x^2*y")?, ["x", "y"])? {
        println!("{}", component);
    }
    println!("{}", session.divergence(&[x, y, z], ["x", "y", "z"])?);
    println!("{}", session.laplacian(&session.parse("x^2 + y^2")?, ["x", "y"])?);
    println!("{}", session.hessian(&session.parse("x^2*y")?, ["x", "y"])?.to_latex()?);
    Ok(())
}