Function Repository Resource:

Numerically evaluate the gradient of a function summed over the eigenvalues of a matrix, with respect to matrix parameters

Contributed by: Carl Woll
 ResourceFunction["NEigenvalueSumGradient"][f, m][x, y, …] finds the gradient of the function f summed over the eigenvalues of the matrix m[x,y,…].

## Details and Options

The function f should be a unary differentiable or symbolic function.
The function m should be a differentiable function of the variables x, y, … that returns a square matrix.
The matrix should be numeric when the variables are numeric.
ResourceFunction["NEigenvalueSumGradient"] works with both symmetric and non-symmetric matrices.
ResourceFunction["NEigenvalueSumGradient"] works with large numerical matrices that are a function of variables x, y, ….

## Examples

### Basic Examples (3)

Define a symmetric matrix function:

 In[1]:=

Find the gradient of the eigenvalue function #Log[#]& summed over the eigenvalues at x=1, y=1:

 In[2]:=
 Out[2]=

Check:

 In[3]:=
 Out[4]=

### Scope (3)

A non-symmetric matrix:

 In[5]:=
 Out[7]=

Find the gradient of the function Sin[#]Log[#]& summed over the eigenvalues at x=1, y=1:

 In[8]:=
 Out[8]=

Check:

 In[9]:=
 Out[10]=

A somewhat large matrix with two parameters:

 In[11]:=

Finding the eigenvalues of even a moderately large matrix with symbolic parameters is slow:

 In[12]:=
 Out[12]=

 In[13]:=
 Out[14]=

Check:

 In[15]:=
 Out[15]=

Very large matrix:

 In[16]:=