以下では、<math>A := \begin{bmatrix} a_{11} & \cdots & a_{1m} \\ \vdots & \ddots & \vdots \\ a_{m1} & \cdots & a_{mm} \end{bmatrix}</math> とおく ==全成分を足す== <math>H := \begin{bmatrix} 1 & \cdots & 1 \\ \vdots & \ddots & \vdots \\ 1 & \cdots & 1 \end{bmatrix}</math> とおく <math>\sum_{i,j} a_{ij} = \mathrm{tr}\{ AH \}</math> ==非対角成分のみ足す== 上の結果から trA を引けば良い。 <math>K := H - I = \begin{bmatrix} 0 & 1 & \cdots & 1 \\ 1 & 0 & 1 & \vdots \\ \vdots & 1 & \ddots & 1 \\ 1 & \cdots & 1 & 0 \end{bmatrix}</math> とおく <math>\sum_{i \neq j} a_{ij} = \mathrm{tr}\{ A H - A \} = \mathrm{tr}\{ A K \}</math>