Home » Program to Find The Transpose of a Given Matrix

Program to Find The Transpose of a Given Matrix

by Online Tutorials Library

Program to find the transpose of a given matrix

Explanation

In this program, we need to find the transpose of the given matrix and print the resulting matrix.

Transpose of a matrix:

Transpose of a matrix can be found by interchanging rows with the column that is, rows of the original matrix will become columns of the new matrix. Similarly, columns in the original matrix will become rows in the new matrix. The operation can be represented as follows:

[ AT ]ij = [ A ]ji  

Program to find the transpose of a given matrix

If the dimension of the original matrix is 2 × 3 then, the dimensions of the new transposed matrix will be 3 × 2.

Algorithm

  1. Declare and initialize a two-dimensional array a.
  2. Calculate the number of rows and columns present in the matrix and store it variables rows and cols respectively.
  3. Declare another array t with reversed dimensions i.e t[cols][rows]. Array t will be used to store the elements of the transposed matrix.
  4. Loop through the array a and convert its rows into columns of matrix t using
    t[ i ][ j ] = a[ j ][ i ];
  5. Finally, display the elements of matrix t.

Solution

Python

Output:

Transpose of given matrix:   1 4 7   2 5 8   3 6 9   

C

Output:

Transpose of given matrix:   1 4 7   2 5 8   3 6 9   

JAVA

Output:

Transpose of given matrix:   1 4 7   2 5 8   3 6 9   

C#

Output:

Transpose of given matrix:   1 4 7   2 5 8   3 6 9   

PHP

Output:

Transpose of given matrix:   1 4 7   2 5 8   3 6 9   

Next Topic#

You may also like