pub fn scalar_potential(
field: &Matrix,
vars: &[&Ex],
) -> Result<Ex, SymplexError>Expand description
Scalar potential φ with ∇φ = F for a conservative Cartesian field.
Works in any dimension. The potential is built by successive
integration: φ = ∫F₁ dx₁ + ∫(F₂ − ∂φ₁/∂x₂) dx₂ + …, and the result is
verified by re-differentiation. The additive constant is zero.
§Errors
SymplexError::InvalidArgumentiffieldis not ann×1column vector withn == vars.len().SymplexError::ComputationFailedif the field is not conservative or an antiderivative could not be found in closed form.
§Examples
use symplex::prelude::*;
use symplex::vector::{gradient, scalar_potential};
let ctx = Context::new();
let (x, y, z) = (ctx.symbol("x"), ctx.symbol("y"), ctx.symbol("z"));
let phi = &(&x * &y) * &z + &x.powi(2);
let f = gradient(&phi, &[&x, &y, &z]);
let recovered = scalar_potential(&f, &[&x, &y, &z]).unwrap();
assert!((&recovered - &phi).expand().is_zero_structural());
// y x̂ − x ŷ is rotational: no potential
let rot = Matrix::col_vector(vec![y.clone(), -&x, ctx.int(0)]);
assert!(scalar_potential(&rot, &[&x, &y, &z]).is_err());