Vector Calculus & Matrix
๐ข Vector Calculus & Matrix Operations
Vector calculus extends differential and integral operators to vector fields (functions that assign a vector to every point in space). Matrix calculus generalizes this to high-dimensional tensors.
๐ข 1. Vector Differential Operators (Del )
The operator (nabla) is a vector of partial derivative operators: .
1. The Gradient ()
Applied to a scalar function , result is a vector field.
- Points in direction of steepest ascent.
2. The Divergence ()
Applied to a vector field , result is a scalar.
- Measures the โoutward flowโ from a point.
3. The Curl ()
Applied to a vector field , result is a vector field.
- Measures the โrotationโ or โswirlโ at a point.
๐ก 2. Matrix Calculus Rules
In machine learning and advanced engineering, we differentiate vectors with respect to other vectors.
1. The Jacobian Matrix ()
When differentiating a vector by another vector , the result is a matrix:
2. Essential Matrix Identities
- Derivative of Linear Form:
- Derivative of Quadratic Form:
- Inverse Matrix: (using Kronecker product ).
๐ด 3. The Tensor Chain Rule
For a composition , the derivative is the product of the individual Jacobians:
๐ฏ 4. Fundamental Theorems of Vector Calculus
- Fundamental Theorem for Line Integrals: .
- Greenโs Theorem: Relates line integrals around a closed curve to double integrals over the enclosed region.
- Stokeโs Theorem: Relates the curl of a vector field over a surface to a line integral around the boundary.
- Divergence Theorem (Gaussโs Theorem): Relates the divergence of a vector field in a volume to the flux through the surface.
๐ก Practical Example: Jacobian calculation in Python
import torch
def f(x):
# Vector-to-vector function
# y1 = x1^2, y2 = x1*x2
return torch.stack([x[0]**2, x[0]*x[1]])
x = torch.tensor([1.0, 2.0], requires_grad=True)
y = f(x)
# Calculating Jacobian manually in PyTorch
jacobian = torch.autograd.functional.jacobian(f, x)
print(f"Jacobian matrix:\n{jacobian}")
# Output should be:
# [[2*x1, 0], => [[2, 0]
# [x2, x1]] => [2, 1]]๐ Key Takeaways
- Vector operators (grad, div, curl) describe field properties.
- The Jacobian represents the โderivativeโ of a mapping.
- Fundamental theorems (Stokeโs, Divergence) link integration in different dimensions.