Have you ever considered how the shortest route to your location is determined by Google Maps? Or how you’re automatically moving the steering wheel will impact the motion of your vehicle when you spin it? Well, it all comes down to the Jacobian Matrix. The Jacobian Matrix is a matrix of partial derivatives of a vector function. The transformation of Jacobian spherical coordinates is where the Jacobian is most commonly used. It addresses the idea of Jacobian spherical coordinates transformation in differentiation. In this article, we’ll be discussing the mathematical concept of the Jacobian Matrix, its formula, determinants, and how we’re using it in our daily lives.
The Jacobian matrix and its determinants are defined for a finite number of functions with the same number of variables, and are referred to as “Jacobian”. It tells us how changes in one set of variables affect another set of variables in a function that maps between different spaces.
In this scenario, the first partial derivative of the same function concerning the variables is found in each row. The matrix can be of either form – a square matrix with an equal number of rows and columns, or a rectangular matrix with an uneven number of rows and columns.
Example: While trekking through a mountain with an upside-down trail, there is usually a direction and a degree of steepness. No matter where you are on the mountain, the Jacobian is like having your guide who tells you how steep your climb will be and which way you are going.
Also Read: Mathematics behind Machine Learning – The Core Concepts you Need to Know
Now, a Jacobian matrix is a matrix consisting of partial derivatives that shows the transformation of an input vector into an output vector by a function. It explains how each output changes with respect to every input variable. For a function f: ℝⁿ → ℝᵐ having total number of m components and n variables, the Jacobian formula can be represented as:
Symbolic Jacobian matrix:Matrix([[2*x, -1], [2*y, 2*x]])
Jacobian at point (2, 3):Matrix([[4, -1], [6, 4]])
Determinant of Jacobian (symbolic):4*x**2 + 2*y
Determinant at point (2, 3):22
Numerical Jacobian at point (2, 3):
[[ 4.000001 -1. ]
[ 6. 4. ]]
Here, the Jacobian Formula will give local linear approximation to a function around a point and give explanation about how the function is stretching, rotating, and transforming space.
In order to understand the Jacobian Matrix fully, we’ll be discussing different foundations of mathematics:
It basically refers to the functions that map points from one space to another. These functions have multiple outputs corresponding to multiple inputs. Such functions give the foundation structures of real-life systems like fluid dynamics.
The Jacobian combines linear algebra and multi-variable calculus. Scalar derivatives tell us about the rate of change in single-variable functions. It also explains about rates of change in functions with multiple inputs and outputs presented in matrix format.
Also Read: 12 Matrix Operations You Should Know While Starting your Deep Learning Journey
The structure and the formatting of a Jacobian matrix explain important information about the representation of the transformation. For a function f: ℝⁿ into ℝᵐ, where ‘n’ represents the input and ‘m’ output, the Jacobian is an ‘m’ by ‘n’ matrix. The entries of the Jacobian matrix denote Jᵢⱼ=∂fᵢ/∂xⱼ , the representation of i’th output functions change with respect to the j’th input variable.
So, the dimensions of a matrix affect the transformation. From a 3D space to a 2D space, Jacobian will have rows equal to outputs and columns equal to inputs, which results in a 2*3 matrix.
The functional behaviour of the Jacobian also explains the visual insights with the algebraic definition. The following interpretation helps us in identifying how the Jacobian matrix describes the local behaviour of functions in geometric terms.
The relationship between the Jacobian and Invertibility proved necessary information. It provided insights into the local behavior of the function at a particular point.
A function is said to be invertible in a neighbourhood whenever the Jacobian is non-singular, its determinant being not equal to zero. Then coinciding with that point we’ll have our Inverse Function theorem. But whenever the Jacobian determinant becomes zero, the output domain undergoes folding, compaction, or localization.
Also Read: A Comprehensive Beginners Guide to Linear Algebra for Data Scientists
Now let’s understand the properties of the Jacobian.
Now, we’ll see three different methods of computing the Jacobian Matrix and transformation of Jacobian spherical coordinates – Analytical Derivation, Numerical Approximation and Automatic Differentiation.
It is the classical way that relies on direct computation of the partial derivatives to produce the Jacobian matrix providing insight into the transformation structure. It is achieved by systematically differentiating each component function with respect to each input variable.
Let’s consider an example where vector function f: ℝⁿ → ℝᵐ with components f₁, f₂, …, fₘ, and variables x₁, x₂, …, xₙ is computed with the partial derivative ∂fi/∂xj for each j=1,2,….n.
J(x) = [
∂f₁/∂x₁ ∂f₁/∂x₂ ... ∂f₁/∂xₙ
∂f₂/∂x₁ ∂f₂/∂x₂ ... ∂f₂/∂xₙ
... ... ... ...
∂fₘ/∂x₁ ∂fₘ/∂x₂ ... ∂fₘ/∂xₙ
]
Example: f(x,y) = (x²-y, 2xy), the partial derivatives evaluated are:
∂f₁/∂x = 2x
∂f₁/∂y = -1
∂f₂/∂x = 2y
∂f₂/∂y = 2x
And by this we can say that the Jacobian matrix observed is:
J(x,y) = [2x -1
2y 2x]
By this method, we can see exact results. However, things can get complicated while dealing with multiple variables at a time or complicated functions where computations are not possible.
Whenever an analytical derivation is either too bulky to carry out or when a function lacks a form expression, numerical methods offer practical alternative solutions that compute partial derivatives using finite differences. The two principal finite difference methods are:
∂fi/∂xⱼ ≈ [f(x₁,...,xⱼ+h,...,xₙ) - f(x₁,...,xⱼ,...,xₙ)]/h
∂fi/∂xⱼ ≈ [f(x₁,...,xⱼ+h,...,xₙ) - f(x₁,...,xⱼ-h,...,xₙ)]/(2h)
Here, h = small step that typically would be of order of 10⁻⁶ for double precision.
It is all about choosing the right size of step to take. Too big brings in approximation errors while small causes numerical instability due to floating point limitations. Advanced techniques using adaptive step sizing or Richardson extrapolation can improve accuracy further.
Automatic differentiation which combines analytical accuracy with computational automation is very high on the list. It is different from the numerical method in that AD computes exact derivatives rather than approximating them which leads to avoiding errors of discretization. The basis principles of automatic differentiation are:
This makes automatic differentiation very accessible and efficient for modern software frameworks such as TensorFlow, PyTorch, JAX. They prefer it for computing Jacobians in machine learning, and optimization problems with the scientific ones.
Let’s see how we can implement a Jacobian matrix and jacobian spherical coordinates using Python. We’ll use both symbolic computation and numerical approximation with SymPy and NumPy respectively.
Import the necessary paths required to run the function.
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
Write the function for symbolic computation with SymPy.
def symbolic_jacobian():
x, y = sp.symbols('x y')
f1 = x**2 - y
f2 = 2*x*y
# Define the function vector
f = sp.Matrix([f1, f2])
X = sp.Matrix([x, y])
# Calculate the Jacobian matrix
J = f.jacobian(X)
print("Symbolic Jacobian matrix:")
print(J)
# Calculate the Jacobian at point (2, 3)
J_at_point = J.subs([(x, 2), (y, 3)])
print("\nJacobian at point (2, 3):")
print(J_at_point)
# Calculate the determinant
det_J = J.det()
print("\nDeterminant of Jacobian (symbolic):")
print(det_J)
print("\nDeterminant at point (2, 3):")
print(det_J.subs([(x, 2), (y, 3)]))
return J, det_J
Write the function for numerical approximation with NumPy.
def numerical_jacobian(func, x, epsilon=1e-6):
n = len(x) # Number of input variables
m = len(func(x)) # Number of output variables
jacobian = np.zeros((m, n))
for i in range(n):
x_plus = x.copy()
x_plus[i] += epsilon
jacobian[:, i] = (func(x_plus) - func(x)) / epsilon
return jacobian
Write the main function for the execution of above function and visualization of transformation.
def f(x):
return np.array([x[0]**2 - x[1], 2*x[0]*x[1]])
# Visualize the transformation
def visualize_transformation():
# Create a grid of points
x = np.linspace(-3, 3, 20)
y = np.linspace(-3, 3, 20)
X, Y = np.meshgrid(x, y)
# Calculate transformed points
U = X**2 - Y
V = 2*X*Y
# Plot original and transformed grid
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 6))
# Original grid
ax1.set_title('Original Space')
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax1.grid(True)
ax1.plot(X, Y, 'k.', markersize=2)
# Add a unit circle
circle = plt.Circle((0, 0), 1, fill=False, color='red', linewidth=2)
ax1.add_artist(circle)
ax1.set_xlim(-3, 3)
ax1.set_ylim(-3, 3)
ax1.set_aspect('equal')
# Transformed grid
ax2.set_title('Transformed Space')
ax2.set_xlabel('u')
ax2.set_ylabel('v')
ax2.grid(True)
ax2.plot(U, V, 'k.', markersize=2)
# Calculate the transformation of the unit circle
theta = np.linspace(0, 2*np.pi, 100)
x_circle = np.cos(theta)
y_circle = np.sin(theta)
u_circle = x_circle**2 - y_circle
v_circle = 2*x_circle*y_circle
ax2.plot(u_circle, v_circle, 'r-', linewidth=2)
# Show the local linear approximation at point (1, 0)
point = np.array([1, 0])
J = numerical_jacobian(f, point)
# Calculate how the Jacobian transforms a small circle at our point
scale = 0.5
transformed_points = []
for t in theta:
delta = scale * np.array([np.cos(t), np.sin(t)])
transformed_delta = J @ delta
transformed_points.append(transformed_delta)
transformed_points = np.array(transformed_points)
# Plot the approximation
base_point_transformed = f(point)
ax2.plot(base_point_transformed[0] + transformed_points[:, 0],
base_point_transformed[1] + transformed_points[:, 1],
'g-', linewidth=2, label='Linear Approximation')
ax2.legend()
plt.tight_layout()
plt.show()
# Execute the functions
symbolic_result = symbolic_jacobian()
point = np.array([2.0, 3.0])
numerical_result = numerical_jacobian(f, point)
print("\nNumerical Jacobian at point (2, 3):")
print(numerical_result)
# Visualize the transformation
visualize_transformation()
The nonlinear mapping f(x,y) = (x²-y, 2xy) is proposed, and the Jacobian properties are highlighted. The original space is shown at left with a uniform grid and a unit circle, while the right map shows the space after transformation, where the circle has morphed into a figure-eight.
The Jacobian matrix is calculated both symbolically (Matrix([[2x, -1], [2y, 2*x]])) and at the numerical point (2,3). It shows a determinant equal to 22. This signifies a large stretch of area locally. Thus, this analysis provides a mathematical view of how the transformation distorts the area. The linearization (green curve) represents the local structure of this nonlinear mapping.
The latest ML frameworks include automatic differentiation tools that compute the Jacobian matrix for us. This is a game changer for complex applications such as:
Calculus, differential geometry, and linear algebra are all disciplines of mathematics that the Jacobian Matrix ties together and applies to real-world applications. From the advanced surgical robots to GPS locations, the Jacobian plays a huge role in making the technology more responsive. It’s an example of how mathematics can both describe our universe and help us interact with it more effectively and efficiently.
A. The determinant gives you information about volume changes and invertibility, while the full matrix provides directional information. Use the determinant when you care about scaling factors and invertibility, and the full matrix when you need to know how directions transform.
A. The gradient is actually a special case of the Jacobian! When your function outputs just one value (a scalar field), the Jacobian is a single row, which is exactly the gradient of that function.
A. Yes! If your function isn’t differentiable at a point, the Jacobian isn’t defined there. This happens at corners, cusps, or discontinuities in your function.
A. When changing coordinate systems (like from Cartesian to polar), the Jacobian determines how areas or volumes transform between the systems. This is essential in multivariable calculus for correctly computing integrals in different coordinate systems.
A. Numerical approximations of the Jacobian can suffer from round-off errors and truncation errors. In critical applications like robotics or financial modeling, sophisticated techniques like automatic differentiation are often used to minimize these errors.