The result of the following is a bit unexpected.
sage: n=3;
sage: D = matrix.diagonal(SR,(var(f'd_{i+1}',domain='real') for i in range(n)))
sage: D
[d_1 0 0]
[ 0 d_2 0]
[ 0 0 d_3]
sage: D.inverse()
[1 0 0]
[0 1 0]
[0 0 1]
Clearly, that's generally not the inverse. The inverse()-method should either produce $1/d_i$ on the diagonal or throw an exception that perhaps it cannot divide by the $d_i$ because they might be zero. That I'd understand. But why the 1s?