Skip to main content

gradient_in

Function gradient_in 

Source
pub fn gradient_in(f: &Ex, vars: &[&Ex], cs: CoordinateSystem) -> Matrix
Expand description

Gradient in the given coordinate system: (∇f)ᵢ = (1/hᵢ) ∂f/∂qᵢ.

§Panics

Panics if vars is empty or a curvilinear system is used with vars.len() != 3.

§Examples

use symplex::prelude::*;
use symplex::vector::{gradient_in, CoordinateSystem};

let ctx = Context::new();
let (r, th, ph) = (ctx.symbol("r"), ctx.symbol("theta"), ctx.symbol("phi"));
// ∇(r² sin θ) = (2r sin θ, r cos θ, 0) in spherical coordinates
let f = &r.powi(2) * &th.sin();
let g = gradient_in(&f, &[&r, &th, &ph], CoordinateSystem::Spherical).simplify();
assert_eq!(g[(0, 0)], &(&r * 2) * &th.sin());
assert_eq!(g[(1, 0)], &r * &th.cos());
assert!(g[(2, 0)].is_zero_structural());