MATLAB - Transpose Operator



Transpose of a matrix is a very commonly used operation on a matrix.

What is Transpose of a matrix?

The transpose of a matrix is obtained by interchanging rows to columns and columns to rows.

Consider you have a matrix A of size 3x3 i.e 3 rows and 3 columns. The transpose of a matrix A is represented by letter T as a subscript to matrix A.

For example matrix A transpose will be AT or A. or A

Let us try one example

A =  1     2     3
     4     5     6
     7     8     9

The transpose of matrix A will be

AT = 
   1     4     7
   2     5     8
   3     6     9

OR

A = 
   1     4     7
   2     5     8
   3     6     9

If you do transpose of the transpose matrix you will get the original matrix.

Let us start with the main Matrix A.

A =
   1     2     3
   4     5     6
   7     8     9

The transpose of matrix A will be

AT = 
     1     4     7
     2     5     8
     3     6     9

Lets transpose it again and you should get the result which is equal to the original matrix we started with.

(AT)T = 
   1     2     3
   4     5     6
   7     8     9

So the equation (AT)T = A or (A) = A.

Transpose Method in Matlab

In matlab you can make use of the operator .' i.e A .' , also using ' i.e A' to find the transpose of the matrix or by using the transpose() method.

Syntax

T  = A .'
T  = A'
T  = transpose(A)

The transpose() method or by using .' or ' will return the transpose of the matrix.

Example 1

Here I will make use of the operator .' to find the transpose of the matrix.

A = [1 2 3; 4 5 6; 7 8 9]
T = A .'

On execution in matlab you get the following output

>> A = [1 2 3; 4 5 6; 7 8 9]

>> T = A.'

A =

   1     2     3
   4     5     6
   7     8     9

T =

   1     4     7
   2     5     8
   3     6     9
>> 

Example 2

Using the operator '

A = [1 2 3; 4 5 6; 7 8 9]
T = A '

On execution in Matlab you will get following output.

>> A = [1 2 3; 4 5 6; 7 8 9]
T = A'

A =
   1     2     3
   4     5     6
   7     8     9
   
T =

   1     4     7
   2     5     8
   3     6     9
>> 

Example 3

Let us now make use of the transpose() method.

A = [1 2 3; 4 5 6; 7 8 9]
T = transpose(A)

On execution the output is −

>> A = [1 2 3; 4 5 6; 7 8 9]
T = transpose(A)

A =

   1     2     3
   4     5     6
   7     8     9

T =

   1     4     7
   2     5     8
   3     6     9
>> 

Transpose on Transpose of Matrix

Let us now try transpose on traponse of the matrix to make sure we get the original matrix back

Example 1

Using the operator (.')

A = [1 2 3; 4 5 6; 7 8 9]
T = (A .').'

When the above code in executed in Matlab the output is as follows −

>> A = [1 2 3; 4 5 6; 7 8 9]
T = (A .').'

A =
   1     2     3
   4     5     6
   7     8     9

T =
   1     2     3
   4     5     6
   7     8     9
>>

Example 2

Using the transpose() method as shown below.

A = [1 2 3; 4 5 6; 7 8 9]
T = transpose(A)
Y = transpose(T)

On execution in matlab the output is −

>> A = [1 2 3; 4 5 6; 7 8 9]
T = transpose(A)
Y = transpose(T)
A =
   1     2     3
   4     5     6
   7     8     9

T =
   1     4     7
   2     5     8
   3     6     9

Y =
   1     2     3
   4     5     6
   7     8     9
>> 

Transpose on Complex Matrix

Let us first construct a complex matrix as shown below.

A = [5 3 4-1i 3+2i; 0+4i 1-2i 5 5-1i]
B = A.'

On execution in Matlab the output is −

>> A = [5 3 4-1i 3+2i; 0+4i 1-2i 5 5-1i]
B = A.'

A =

   5 + 0i   3 + 0i   4 - 1i   3 + 2i
   0 + 4i   1 - 2i   5 + 0i   5 - 1i

B =

   5 + 0i   0 + 4i
   3 + 0i   1 - 2i
   4 - 1i   5 + 0i
   3 + 2i   5 - 1i

>> 

Transposing the matrix B again gives back the original matrix as shown below.

>> B = B.'

B =

   5.0000 + 0.0000i   3.0000 + 0.0000i   4.0000 - 1.0000i   3.0000 + 2.0000i
   0.0000 + 4.0000i   1.0000 - 2.0000i   5.0000 + 0.0000i   5.0000 - 1.0000i

>> 

Difference between transpose operator (.') and (') ?

The operator .' follows non-conjugate transpose.

The operator ' follows conjugate transpose.

The above operators affect more on complex matrices.Since the operator .' is meant for non-conjugate transpose; it will make sure it does not affect the sign of the imaginary parts of the complex number. Whereas the sign of the imaginary parts of complex numbers will be affected when the operator(') is used.

Let us check the matrix with complex numbers and the output of transpose with (.') and (').

Let us consider the below matrix to test on both operators.

A = [5 3 4-1i 3+2i; 0+4i 1-2i 5 5-1i]

Conjugate transpose (')

The conjugate transpose of a matrix, also known as the Hermitian transpose or adjoint, is a mathematical operation that involves taking the transpose of a matrix and then replacing each element with its complex conjugate.

The complex conjugate of a complex number a + bi is formed by changing the sign of the imaginary part, resulting in a - bi. However, for real numbers, the complex conjugate remains unchanged.

>> A = [5 3 4-1i 3+2i; 0+4i 1-2i 5 5-1i]
B = A'

A =

   5.0000 + 0.0000i   3.0000 + 0.0000i   4.0000 - 1.0000i   3.0000 + 2.0000i
   0.0000 + 4.0000i   1.0000 - 2.0000i   5.0000 + 0.0000i   5.0000 - 1.0000i

B =

   5.0000 + 0.0000i   0.0000 - 4.0000i
   3.0000 + 0.0000i   1.0000 + 2.0000i
   4.0000 + 1.0000i   5.0000 + 0.0000i
   3.0000 - 2.0000i   5.0000 + 1.0000i

>> 

Non-Conjugate transpose (.')

You will very rarely come across "Non-Conjugate transpose" term, it refers to a tranpose operatoon that does not consider the complex conjugate of the matrix elements.

>> A = [5 3 4-1i 3+2i; 0+4i 1-2i 5 5-1i]
B = A.'

A =

   5.0000 + 0.0000i   3.0000 + 0.0000i   4.0000 - 1.0000i   3.0000 + 2.0000i
   0.0000 + 4.0000i   1.0000 - 2.0000i   5.0000 + 0.0000i   5.0000 - 1.0000i


B =

   5.0000 + 0.0000i   0.0000 + 4.0000i
   3.0000 + 0.0000i   1.0000 - 2.0000i
   4.0000 - 1.0000i   5.0000 + 0.0000i
   3.0000 + 2.0000i   5.0000 - 1.0000i

>>

Another method that can be used to work on complex conjugate transpose is ctranpose().

Syntax

B = A'
B = ctranspose(A)

This method is rarely used as you can directly go and make use of A . The ctranspose() is another alternative to give you the transpose of the matrix.

Let us see a few examples using ctranspose().

Example 1

Consider the following matrix.

A = [1 2 3; 4 5 6; 7 8 9]
B = ctranspose(A)

On execution the output is −

>> A = [1 2 3; 4 5 6; 7 8 9]
B = ctranspose(A)

A =

   1     2     3
   4     5     6
   7     8     9

B =

   1     4     7
   2     5     8
   3     6     9

>> 

Example 2

In this example will take a complex matrix as shown below.

A = [0-2i 4+1i;4+3i 0-2i]
B = ctranspose(A)

On execution in matlab the output is −

>> A = [0-2i 4+1i;4+3i 0-2i]
B = ctranspose(A)

A =

   0 - 2i   4 + 1i
   4 + 3i   0 - 2i

B =

   0 + 2i   4 - 3i
   4 - 1i   0 + 2i

>>
Advertisements