Chapter 7 — Vector Calculus
Vector calculus extends calculus to functions that have vector outputs or inputs. It is important in ML for understanding advanced optimization, physics-based simulations, and some reinforcement learning environments.
7.1 What is Vector Calculus?
Vector calculus deals with differentiation and integration of vector fields. A vector field assigns a vector to every point in space, e.g., F(x, y, z) = (P(x, y, z), Q(x, y, z), R(x, y, z)).
Importance in ML: Vector calculus is useful in understanding gradient flows, optimization in high-dimensional spaces, and modeling physics-based environments in reinforcement learning.
7.2 Divergence
Divergence measures how much a vector field spreads out from a point:
div F = ∇ · F = ∂P/∂x + ∂Q/∂y + ∂R/∂z
Example: For F(x, y, z) = (x², y², z²), divergence is 2x + 2y + 2z.
7.3 Curl
Curl measures the rotation or circulation of a vector field:
curl F = ∇ × F =
( ∂R/∂y - ∂Q/∂z,
∂P/∂z - ∂R/∂x,
∂Q/∂x - ∂P/∂y )
Example: For F(x, y, z) = (-y, x, 0), curl F = (0, 0, 2) → indicates rotation around z-axis.
7.4 Line Integrals
Line integrals compute the integral of a vector field along a curve C:
∫_C F · dr
Example: Work done by a force along a path, F = (y, x), along line from (0,0) → (1,1).
7.5 Surface Integrals
Surface integrals compute flux of a vector field through a surface S:
∬_S F · dS
Example: Flux of F = (x, y, z) through unit square in xy-plane = 1.
7.6 Applications in Machine Learning
- Physics-based simulations: In reinforcement learning environments with fluid dynamics, forces, or electromagnetic fields.
- Optimization insights: Gradients in high-dimensional spaces can be interpreted via divergence and curl to analyze flow of optimization steps.
- Vector field visualization: Understanding vector flows helps in designing control policies for RL agents.
7.7 Quick Python Examples
Using SymPy for divergence and curl:
from sympy import symbols, diff
from sympy.vector import CoordSys3D, divergence, curl
x, y, z = symbols('x y z')
N = CoordSys3D('N')
# Define vector field F = x^2 i + y^2 j + z^2 k
F = x**2*N.i + y**2*N.j + z**2*N.k
# Divergence
div_F = divergence(F, N)
print("Divergence:", div_F)
# Curl
curl_F = curl(F, N)
print("Curl:", curl_F)
7.8 Exercises
- Compute divergence of
F = (xy, yz, zx). - Compute curl of
F = (z, x, y). - Compute line integral of
F = (y, -x)along a circle of radius 1 centered at origin. - Compute surface integral of
F = (x, y, z)over unit square in xy-plane.
Answers / Hints
- div F = y + z + x
- curl F = (-1, -1, -1)
- Line integral = 2π (path is circle, use param x=cos(t), y=sin(t))
- Surface integral = 1
7.9 Practice Projects / Mini Tasks
- Visualize a 2D vector field using quiver plots in matplotlib.
- Simulate a simple RL environment with force fields and compute work along trajectories.
- Experiment with divergence and curl of random vector fields to understand local behavior.
7.10 Further Reading & Videos
- Khan Academy — Vector Calculus (Divergence, Curl)
- MIT OCW — Multivariable Calculus (Vector Fields)
- SymPy Documentation — Divergence, Curl, Line and Surface Integrals
- Reinforcement Learning texts — Vector fields in continuous action spaces
Next chapter: Gradient, Hessian & Jacobian Applications — key tools for optimization in ML and neural network training.