The Hessian Matrix: A Quick Guide
The Hessian matrix (or Hessian) of a scalar-valued multivariable function ( f: \mathbb{R}^n \to \mathbb{R} ) is the ( n \times n ) symmetric matrix of second-order partial derivatives. It captures the local curvature of the function and is crucial for classifying critical points (e.g., minima, maxima, saddles) via its eigenvalues or definiteness.
General Form
For ( f(\mathbf{x}) ) where ( \mathbf{x} = (x_1, x_2, \dots, x_n) ),
[
H_f(\mathbf{x}) =
\begin{bmatrix}
\frac{\partial^2 f}{\partial x_1^2} & \frac{\partial^2 f}{\partial x_1 \partial x_2} & \cdots & \frac{\partial^2 f}{\partial x_1 \partial x_n} \
\frac{\partial^2 f}{\partial x_2 \partial x_1} & \frac{\partial^2 f}{\partial x_2^2} & \cdots & \frac{\partial^2 f}{\partial x_2 \partial x_n} \
\vdots & \vdots & \ddots & \vdots \
\frac{\partial^2 f}{\partial x_n \partial x_1} & \frac{\partial^2 f}{\partial x_n \partial x_2} & \cdots & \frac{\partial^2 f}{\partial x_n^2}
\end{bmatrix}
]
By Clairaut's theorem (assuming sufficient smoothness), ( H ) is symmetric: ( H_{ij} = H_{ji} ).
How to Compute It (Step-by-Step)
- Compute all first partials ( \frac{\partial f}{\partial x_i} ).
- Differentiate each first partial again w.r.t. every ( x_j ).
- Assemble into the matrix.
Example 1: 2D Function
Let ( f(x, y) = x^2 y + 3xy^2 - \sin(x) + e^y ).
-
First partials:
[
f_x = 2xy + 3y^2 - \cos(x), \quad f_y = x^2 + 6xy + e^y
]
-
Second partials:
[
f_{xx} = 2y + \sin(x), \quad f_{xy} = f_{yx} = 2x + 3y^2 + 6x = 8x + 3y^2? \quad \wait, \let me \calc properly.
]
Wait, correction:
[
f_{xy} = \frac{\partial}{\partial y}(2xy + 3y^2 - \cos x) = 2x + 6y
]
[
f_{yy} = \frac{\partial}{\partial y}(x^2 + 6xy + e^y) = 6x + e^y
]
[
f_{yx} = \frac{\partial}{\partial x}(x^2 + 6xy + e^y) = 2x + 6y \quad (\text{symmetric})
]
-
Hessian:
[
H_f(x,y) =
\begin{bmatrix}
2y + \sin x & 2x + 6y \
2x + 6y & 6x + e^y
\end{bmatrix}
]
Example 2: 3D Function
Let ( f(x,y,z) = x^2 + y^2 z + \frac{1}{2} z^2 ).
Hessian:
[
H_f =
\begin{bmatrix}
2 & 0 & 0 \
0 & z & 1 \
0 & 1 & z + 1? \wait.
\end{bmatrix}
No:
f_{xx}=2, f_{xy}=0, f_{xz}=0
f_{yx}=0, f_{yy}=z? f_y = 2y z? f= x^2 + y^2 z + (1/2)z^2
f_x = 2x, f_y = 2 y z, f_z = y^2 + z
Then:
f_{xx}=2, f_{xy}=0, f_{xz}=0
f_{yx}=0, f_{yy}=2z, f_{yz}=2y
f_{zx}=0, f_{zy}=2y, f_{zz}=1
Yes:
[
H_f =
\begin{bmatrix}
2 & 0 & 0 \
0 & 2z & 2y \
0 & 2y & 1
\end{bmatrix}
]
Usage Tip
At a critical point ( \nabla f = \mathbf{0} ):
- ( H ) positive definite → local min
- Negative definite → local max
- Indefinite → saddle
Need the Hessian for a specific function? Drop the function here (e.g., "f(x,y) = x^2 + xy + y^2"), and I'll compute it precisely, Sherlock-style. 🔍