Skip to main content

Module vector

Module vector 

Source
Expand description

Vector calculus: gradient, divergence, curl, laplacian. Vector calculus: gradient, divergence, curl, Laplacian (in Cartesian, cylindrical and spherical coordinates), directional derivatives, line integrals and scalar potentials.

Scalar fields are Ex; vector fields are n×1 column-vector Matrix values whose components are expressed in the coordinate basis of the chosen CoordinateSystem (e.g. (F_r, F_φ, F_z) for cylindrical coordinates).

§Coordinate conventions

Systemvars orderScale factors (h₁, h₂, h₃)
Cartesian(x, y, z) (any dimension)(1, 1, 1)
Cylindrical(r, φ, z)(1, r, 1)
Spherical(r, θ, φ)physics convention: θ polar angle from +z, φ azimuth(1, r, r·sin θ)

The Cartesian functions (gradient, divergence, curl, laplacian) work in any dimension (curl: 3-D only). The _in variants take an explicit coordinate system; the curvilinear systems are 3-D and require exactly three variables.

§Shape preconditions

Wrong field dimensions / variable counts are programming errors and panic (like slice indexing), consistent with the rest of this module. Mathematical failure (e.g. a non-conservative field passed to scalar_potential) returns Err.

Enums§

CoordinateSystem
Orthogonal coordinate systems supported by the vector-calculus operators.

Functions§

curl
Curl of a 3-D vector field in Cartesian coordinates: ∇×F.
curl_in
Curl in the given coordinate system:
directional_derivative
Directional derivative ∇f · d of f along the (Cartesian) direction vector d.
divergence
Divergence of a vector field in Cartesian coordinates: ∇·F = Σᵢ ∂Fᵢ/∂xᵢ.
divergence_in
Divergence in the given coordinate system: ∇·F = (1/(h₁h₂h₃)) Σᵢ ∂/∂qᵢ ( (h₁h₂h₃/hᵢ) Fᵢ ).
gradient
Gradient of a scalar field in Cartesian coordinates: ∇f = [∂f/∂x₁, …, ∂f/∂xₙ]ᵀ (an n×1 column vector).
gradient_in
Gradient in the given coordinate system: (∇f)ᵢ = (1/hᵢ) ∂f/∂qᵢ.
hessian
Hessian matrix H[i][j] = ∂²f / ∂vars[i] ∂vars[j].
is_conservative
Is the 3-D vector field conservative (curl-free)? Three-valued.
is_irrotational
Alias of is_conservative (irrotational ⇔ curl-free).
is_solenoidal
Is the vector field solenoidal (divergence-free)? Three-valued, like is_conservative.
laplacian
Laplacian of a scalar field in Cartesian coordinates: ∇²f = Σᵢ ∂²f/∂xᵢ².
laplacian_in
Laplacian ∇²f = ∇·(∇f) in the given coordinate system.
line_integral_scalar
Scalar line integral ∫_C f ds = ∫ₐᵇ f(r(t)) ‖r′(t)‖ dt.
line_integral_vector
Vector line integral (work) ∫_C F·dr = ∫ₐᵇ F(r(t)) · r′(t) dt.
scalar_potential
Scalar potential φ with ∇φ = F for a conservative Cartesian field.