Find the first derivative of a SUM of all elements of an INVERSE of a square matrix (whose elements are functions of $z$) at $z=1$ knowing that all of the matrix' elements evaluate to $1$ at $z=1$.


This is needed in Statistics to find the expected number of trials to generate one of several preselected patterns (such as 3 consecutive sixes when rolling a die, etc.)


I believe the answer is: $-$ the reciprocal of the SUM of all elements of the inverse of the matrix of first derivatives (evaluated at $z=1$) but I don't know how to prove it (I have verified it up to 5 by 5 - quite difficult to go any higher).


P.S. What is the second derivative?



Derivative involving a singular matrix
I first rephrase the question using formulas and then will provide a proof.


Start from the $n\times n$ matrix $A(z)$, such that $[A(1)]\_{ij}=1$ for all $i,j\in\{1,2,\ldots n\}$. The matrix $B(z)$ is the elementwise derivative, $B\_{ij}=dA\_{ij}/dz$.  

Now the question which the OP asks is whether
$$\lim\_{z\rightarrow 1}\frac{d}{dz}\sum\_{i,j=1}^n [A^{-1}(z)]\_{ij}=-\left(\lim\_{z\rightarrow 1}\sum\_{i,j=1}^n[B^{-1}(z)]\_{ij}\right)^{-1}\qquad\qquad(\ast)$$


For a proof I decompose $A=(z-1)B+v^\top v$, where $v=(1,1,1,\ldots 1)^\top$. I apply the [Woodbury identity](https://en.wikipedia.org/wiki/Woodbury_matrix_identity),
$$A^{-1}=[(z-1)B+v^\top v]^{-1}=(z-1)^{-1}B^{-1}\left[1-v^\top \bigl(z-1+vB^{-1}v^\top\bigr)^{-1}vB^{-1}\right]$$
$$\Rightarrow\sum\_{i,j=1}^n [A^{-1}]\_{ij}=vA^{-1}v^\top=\frac{vB^{-1}v^\top}{vB^{-1}v^\top+z-1}$$
$$\Rightarrow\lim\_{z\rightarrow 1}\frac{d}{dz}\sum\_{i,j=1}^n [A^{-1}]\_{ij}=-\frac{1}{vB^{-1}v^\top}=-\left(\sum\_{i,j=1}^n[B^{-1}]\_{ij}\right)^{-1},$$
which is the equation ($\ast$).




---


The OP also asks about second derivatives. Define $C\_{ij}=d^2A\_{ij}/dz^2$ and decompose $A=(z-1)B+\tfrac{1}{2}(z-1)^2C+v^\top v$. The Woodbury identity gives
$$vA^{-1}v^\top=\frac{vX^{-1}v^\top}{vX^{-1}v^\top+z-1},$$
$$X=B+\tfrac{1}{2}(z-1)C\Rightarrow X^{-1}=B^{-1}-\tfrac{1}{2}(z-1)B^{-1}C B^{-1}+{\cal O}(z-1)^2.$$
Thus we obtain the second derivative from
$$\lim\_{z\rightarrow 1}\frac{d^2}{dz^2}\sum\_{i,j=1}^n [A^{-1}]\_{ij}=\frac{2-vB^{-1}C B^{-1}v^\top}{(vB^{-1}v^\top)^2}.$$


