hessian matrix calculator

Use explicit multiplication: 3*x*y. Supported functions: sin, cos, tan, exp, log, sqrt, abs, pow. You may use ^ for powers.

What is a Hessian matrix?

The Hessian matrix is a square matrix of second-order partial derivatives of a scalar function. For a two-variable function f(x,y), it captures how curvature changes in each direction and across directions. It is one of the most important objects in multivariable calculus, optimization, machine learning, and physics.

Definition (two variables)

For f(x,y), the Hessian at a point (x,y) is:
H(x,y) = [[f_xx, f_xy], [f_yx, f_yy]]

Under standard smoothness assumptions, mixed partials are equal, so f_xy = f_yx, making the Hessian symmetric.

How this hessian matrix calculator works

This calculator evaluates the Hessian numerically using central-difference formulas:

  • f_xx ≈ (f(x+h,y) - 2f(x,y) + f(x-h,y)) / h²
  • f_yy ≈ (f(x,y+h) - 2f(x,y) + f(x,y-h)) / h²
  • f_xy ≈ (f(x+h,y+h) - f(x+h,y-h) - f(x-h,y+h) + f(x-h,y-h)) / (4h²)

It then reports:

  • The Hessian matrix entries
  • Determinant and trace
  • Eigenvalues (real or complex pair)
  • Second-derivative test classification at the selected point

How to interpret the output

Second-derivative test for 2D

Let D = f_xx f_yy - (f_xy)^2.

  • If D > 0 and f_xx > 0, the point is a local minimum.
  • If D > 0 and f_xx < 0, the point is a local maximum.
  • If D < 0, the point is a saddle point.
  • If D = 0 (or very close), the test is inconclusive.

Practical tips

  • Choose a reasonable step size h (default 1e-4 is a good start).
  • If the result is unstable, try slightly larger or smaller h.
  • Avoid points where your function is undefined (for example, log(x) at x ≤ 0).
  • Use parentheses generously for clarity, e.g. sin(x)*cos(y).

Where Hessians are used

Hessian matrices appear in many technical fields:

  • Optimization: Newton and quasi-Newton methods use curvature for fast convergence.
  • Machine learning: Curvature helps diagnose sharp/flat minima and training dynamics.
  • Economics: Utility and profit surface curvature supports local optimality analysis.
  • Engineering: Stability and sensitivity studies rely on second-order behavior.

Example

For f(x,y)=x²+3xy+y², the Hessian is constant: [[2,3],[3,2]]. Its determinant is 4-9=-5, which is negative, so any critical point is a saddle point. Load the "Quadratic" example above to verify numerically.

🔗 Related Calculators