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>>,: 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>>,; 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>>,. 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>>,.
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 (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 matrix of second partials, computed as the Jacobian of the gradient; structurally symmetric on smooth input.
Example#
Differential operators over an ordered coordinate list.
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(())
}