How to adjust the diagonal so that a matrix is on the stability threshold? I am working on the stability of food webs, which can be represented by a Jacobian matrix showing the interaction strengths between species. I know that a matrix is locally stable if all real parts of the eigenvalues are negative, and I know how to find these eigenvalues.

I now want to adjust the diagonal of my matrix so that the matrix is on the threshold of stability: it is stable, but any loss of intraspecific interaction - which are the values on the diagonal - will result in an unstable matrix. Mathematically speaking I think I want a matrix with an adjusted diagonal so that all eigenvalues are zero - does this makes sense?

Is there a method to find out what my diagonal should look like if I want all my eigenvalues to be zero? The starting point for the transformation can be any diagonal (i.e. all values are -1, or all values differ according to some biological data).

In literature I found "An eigenvalue $\lambda_{i}$ can be linearly transformed by the amount that must be subtracted from $a_{ii}$ to allow the eigenvalue to be 0 (by $-|\lambda_{i}-a_{ii}|)"$, but I'm not sure how to implement this.

I hope this is the right way of asking the question; first time I use this platform!
To be on the boundary of instability, you don't need all eigenvalues to be zero, you just need the largest occuring real part to be zero (so that the “rightmost” eigenvalue(s) is (are) on the imaginary axis).

This you can do by adding $cI$ to your matrix (where I is the identity matrix, and $c$ is a suitable constant); this will add $c$ to all the eigenvalues, i.e., shift them $c$ steps to the right in the complex plane.
To be on the boundary of instability, you don't need all eigenvalues to be zero, you just need the largest occuring real part to be zero (so that the “rightmost” eigenvalue(s) is (are) on the imaginary axis).

This you can do by adding $cI$ to your matrix (where I is the identity matrix, and $c$ is a suitable constant); this will add $c$ to all the eigenvalues, i.e., shift them $c$ steps to the right in the complex plane.