vector - Transform an upper triangular matrix into a full matrix C++ -
vector - Transform an upper triangular matrix into a full matrix C++ -
how code can transform upper triangular matrix total matrix. matrix in vector, not in bidimensional array...
so array
[ 1 2 3 4 0 5 6 7 0 0 8 9 0 0 0 10 ]
would become array like:
[ 1 2 3 4 2 5 6 7 3 6 8 9 4 7 9 10 ]
could provide ideas, thinking in applying kind of module or something...
there 1 restriction, i not using bidimensional arrays usng vector, unidimensional array
first, must understand fundemtnal nature of reflected matrix. i
, j
, next assertion true:
m[i][j] ≡ m[j][i]
so, need algorithm create true. may suggest:
for(int = 0; < height; ++i) for(int j = 0; j < i; ++j) m[i][j] = m[j][i];
note status of 2nd loop. ensuring j
less i
, restrict our activity bottom-left triangle.
next, must understand how have implemented two-dimensional matrix in one-dimensional array. appears have established identity:
m[i][j] ≡ v[i*width+j]
substituting, have:
for(int = 0; < height; ++i) for(int j = 0; j < i; ++j) v[i*width+j] = v[j*width+i];
c++ vector matrix
Comments
Post a Comment