Linear algebra-matrices-transpose C and C + + implementations

Source: Internet
Author: User

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:

    1. Use Getspecifiedrow () to remove the line I from this matrix and place it in the vector Tempvec;
    2. Use Addonecolumtoback () to put the above Tempvec into the column of the temporary matrix Tempmatrix;
    3. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.