Principle Analysis:
This section describes the transpose of the Matrix. The transpose of the matrix will change the row and column elements of the matrix, that is, the first column of the second row (with C21, after the same) and the first row of the second column (C12) element swap position, the original C31 and C13 Exchange. namely CIJ and cji Exchange.
(Fill in the illustration here)
C + + language:
The first thing we think about is to remove the column J of row I from Row J, which is simple enough to say.
Here is another way of thinking about the whole row of columns, as follows:
- Use Getspecifiedrow () to remove the line I from this matrix and place it in the vector Tempvec;
- Use Addonecolumtoback () to put the above Tempvec into the column of the temporary matrix Tempmatrix;
- Replace this matrix with temporary tempmatrix;
Template <typename t>Matrix<T> matrix<t>:: Transpose () {Matrix<T>Tempmatrix; Vector<T>Tempvec; /*Get Transpose*/ for(intI=0; i<m_icolumns;i++) { This->getspecifiedrow (i,&Tempvec); Tempmatrix.addonecolumtoback (Tempvec); } /*swap rows and columns*/M_vecmatrix=Tempmatrix.m_vecmatrix; inttemp =M_icolumns; M_icolumns=m_irows; M_irows=temp; returnTempmatrix;}
Linear algebra-matrices-transpose C and C + + implementations