I want to store in an array a symmetric matrix
for a matrix I was doing this
double[,] mat = new double[size,size];
for (int i = 0; i < s
Regarding the selected answer, unless I am being a complete idiot the code isn't correct:
Try this:
i = 2, j = 1
therefore we use:
k(i,j) = j*N-j*(j-1)/2+i
to find the index k, solving:
k(i,j) = 1*5 - 1*(1-1)/2 + 2
k(i,j) = 5 - 0 + 2 = 7
From the matrix in the selected answer we see that (2,1) is not 7, it seems to be 6. In fact (since this seems to be 0-base), 7 occurs at (3,1) or (1,3). The second formula for i > j seems to be inaccurate unless I am missing something.
UPDATE:
This seems to work if you alter the i > j formula to:
k(i,j) = j*(N-1)-j*(j-1)/2+i