I want to make a table to get a nbyn matrix. However, the diagonal are divided by zero. For example:
n = 5;
Table[1/(Sin[i] - Sin[j]), {i, 1., n}, {j, 1, n}]
I can use IF statement, however, is there any more elegant way to set diagonal elements to zero or any other default value?
One solution is, if the matrix is symmetric:
m = Table[0,{i,1,n},{j,1,n}];
Table[m[[i,j]] = 1/(Sin[i] - Sin[j]), {i, 1., n-1}, {j, i+1, n}]
Table
in the post should be aDo
:) $\endgroup$Table[(1 - KroneckerDelta[i, j])/(Sin[i] - Sin[j] + KroneckerDelta[i, j]), {i, 5}, {j, 5}]
. $\endgroup$Table
? $\endgroup$I
to prevent the denumerator becomes zero accidentally. $\endgroup$