...

/

Second-Order Derivatives and the Hessian

Second-Order Derivatives and the Hessian

Learn what second-order derivatives are and how to calculate the Hessian of a function.

As derivatives are functions, they have their own derivatives. The derivative of a derivative is called a second-order derivative. In the following code, we calculate the second-order derivative of f=x2f = x^2.

Press + to interact
from sympy import symbols, diff
x = symbols('x')
f = x**2
df = diff(f, x) # first-order derivative
ddf = diff(df, x) # second-order derivative
print("First-order:", df)
print("Second-order:", ddf)

Second-order derivatives in multiple dimensions

In cases with more than one variable, we can calculate the second-order derivative with respect to the same first variable or with respect to another variable. For example, we denote as 2fx2\frac{\partial^2 f}{\partial x^2} the operation of taking the derivative of ff with respect to xx and then taking again the derivative with respect to xx. But we could take the second derivative with respect to another variable. We denote as 2fxy\frac{\partial^2 f}{\partial x\partial y} when we first take the derivative with respect to xx and then with respect to ...