# How to find the transpose of the complex 2d matrix

Page 1 of 1

## 4 Replies - 1630 Views - Last Post: 20 February 2012 - 08:56 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=267420&amp;s=e1127bf29627544b12d6da14ceadaf5e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 [email protected]

Reputation: 0
• Posts: 3
• Joined: 20-January 11

# How to find the transpose of the complex 2d matrix

Posted 20 February 2012 - 06:26 AM

How to find the transpose of the complex 2d matrix
Is This A Good Question/Topic? 0

## Replies To: How to find the transpose of the complex 2d matrix

### #2 Karel-Lodewijk

Reputation: 454
• Posts: 864
• Joined: 17-March 11

## Re: How to find the transpose of the complex 2d matrix

Posted 20 February 2012 - 06:30 AM

The same way you would take the transpose of an ordinary matrix, only with a matrix that has complex entries.

### #3 [email protected]

Reputation: 0
• Posts: 3
• Joined: 20-January 11

## Re: How to find the transpose of the complex 2d matrix

Posted 20 February 2012 - 07:42 AM

Actually, i have to construct my complex matrix by using struct, so there will be a real part and imag part to it
So, i suppose its transpose wont be similar to a normal matrix transpose.
If you can guide me along, it would be nice of you.
thanks

### #4 ishkabible

• spelling expret

Reputation: 1747
• Posts: 5,898
• Joined: 03-August 09

## Re: How to find the transpose of the complex 2d matrix

Posted 20 February 2012 - 07:49 AM

it's the same thing so long as you define the arithmetic behavior of the complex number(add, sub, multiply, divide, etc...)

also, C++ has a complex number library. double and complex<double> can do all the same things but complex<double> defines an imaginary part.

This post has been edited by ishkabible: 20 February 2012 - 07:51 AM

### #5 Karel-Lodewijk

Reputation: 454
• Posts: 864
• Joined: 17-March 11

## Re: How to find the transpose of the complex 2d matrix

Posted 20 February 2012 - 08:56 AM

An algorithm for a simple square matrix implemented using a 2D array could look something like this:

```#include <complex>
#include <algorithm>
#include <iostream>

const size_t DIM = 3;

int main() {
std::complex<double> matrix[DIM][DIM] = {{1+1i,2,3},{4,5+3i,6},{7,8,9}};

for (size_t i = 0; i < DIM-1; ++i)
for (size_t j = i+1; j < DIM; j++)
std::swap(matrix[i][j], matrix[j][i]);

for (size_t i = 0; i < DIM; ++i) {
for (size_t j = 0; j < DIM; ++j)
std::cout << matrix[i][j] << " ";
std::cout << std::endl;
}
}

```

edit: [] used for array indices
edit2: tested it, posted running version, works ok

This post has been edited by Karel-Lodewijk: 20 February 2012 - 09:08 AM