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:
Took me some time to understand what you needed! :)
unsigned int row_index(int i, int m)
{
int iCurrentRow = 0;
int iTotalItems = 0;
for(int j = m; j > 0; j--)
{
iTotalItems += j;
if( (i+1) <= iTotalItems)
return iCurrentRow;
iCurrentRow ++;
}
return -1; // Not checking if "i" can be in a MxM matrix.
}
Sorry forgot the other function.....
unsigned int column_index(int i, int m)
{
int iTotalItems = 0;
for(int j = m; j > 0; j--)
{
iTotalItems += j;
if( (i+1) <= iTotalItems)
return m - (iTotalItems - i);
}
return -1; // Not checking if "i" can be in a MxM matrix.
}