Skip to Content

HESSIAN_MATRIX

Overview

Computes the Hessian matrix (second derivatives) of a scalar function with respect to its variables. This function enables business users to analyze curvature, perform advanced optimization, and understand the local behavior of functions directly in Excel. It leverages the CasADi package for symbolic and numeric differentiation, and is accessible via the Boardflare Python for Excel add-in.

The Hessian matrix HH of a scalar function f(x)f(\mathbf{x}) with respect to variables x=[x1,x2,,xn]\mathbf{x} = [x_1, x_2, \ldots, x_n] is defined as:

Hij=2fxixjH_{ij} = \frac{\partial^2 f}{\partial x_i \partial x_j}

or, in matrix form:

H(f)=[2fx122fx1xn2fxnx12fxn2]H(f) = \begin{bmatrix} \frac{\partial^2 f}{\partial x_1^2} & \cdots & \frac{\partial^2 f}{\partial x_1 \partial x_n} \\ \vdots & \ddots & \vdots \\ \frac{\partial^2 f}{\partial x_n \partial x_1} & \cdots & \frac{\partial^2 f}{\partial x_n^2} \end{bmatrix}

This function parses the symbolic expression, constructs symbolic variables, and uses CasADi to compute the Hessian matrix symbolically. The resulting Hessian is then evaluated at the provided point (the values for each variable) and returned as a 2D list. This allows for efficient and accurate computation of second-order derivatives, which are essential for optimization, sensitivity analysis, and understanding the curvature of functions.

Usage

To use the HESSIAN_MATRIX function in Excel, enter it as a formula in a cell, specifying your function, variable values, and variable names:

=HESSIAN_MATRIX(expression, variables, [variable_names])

Arguments

ArgumentTypeRequiredDescriptionExample
expressionstringYesSymbolic expression for the scalar function."x**2 + 3*x*y + y**2"
variables2D list floatYesPoint at which to evaluate the Hessian (values for each variable).[[1.0, 2.0]]
variable_names2D list stringNoNames of the variables (if not inferred from the expression).[["x", "y"]]

Returns

TypeDescriptionExample
list[list[float]]The Hessian matrix evaluated at the given point.[[2.0, 3.0], [3.0, 2.0]]
strError message if the calculation fails or input is invalid."Invalid input: expression must be a valid scalar function."

Examples

Risk Analysis in Finance

Business context: A financial analyst wants to compute the Hessian of a risk function to understand how portfolio risk changes with respect to asset allocations.

Excel usage:

=HESSIAN_MATRIX("x**2 + 3*x*y + y**2", {1.0, 2.0}, {"x", "y"})

Expected outcome: Returns the Hessian matrix at the point (1.0, 2.0):

2.03.0
3.02.0

Legend:

H=[2fx22fxy2fyx2fy2]H = \begin{bmatrix} \frac{\partial^2 f}{\partial x^2} & \frac{\partial^2 f}{\partial x \partial y} \\ \frac{\partial^2 f}{\partial y \partial x} & \frac{\partial^2 f}{\partial y^2} \end{bmatrix}

Engineering Design Sensitivity

Business context: An engineer analyzes the curvature of a cost function to assess sensitivity to design variables.

Live Notebook

Edit this function in a live notebook.

Live Demo

Last updated on