I think this must be simple but I can\'t get it right...
I have an MxM triangular matrix, the coefficients of which are stored in a vector, row by row. For example:
There may be a clever one liner for these, but (minus any error checking):
unsigned int row_index( unsigned int i, unsigned int M ){
unsigned int row = 0;
unsigned int delta = M - 1;
for( unsigned int x = delta; x < i; x += delta-- ){
row++;
}
return row;
}
unsigned int column_index( unsigned int i, unsigned int M ){
unsigned int row = 0;
unsigned int delta = M - 1;
unsigned int x;
for( x = delta; x < i; x += delta-- ){
row++;
}
return M + i - x - 1;
}