2 Replies - 185 Views - Last Post: 17 July 2012 - 11:25 AM Rate Topic: -----

#1 erkant  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 108
  • Joined: 26-October 10

Complex structure question

Posted 17 July 2012 - 06:29 AM

I have a question regarding the Complex structure that I have created, below is a short code and my question:

typedef struct {
    int real, img;
} Complex;

Complex matrix[2][3] = {{9511 + 31356j, 12539 + 30273j, -32610 - 3211j},
                        {32767, -32768j, 6392 - 32138j}};


So this is a small example. In my real code I have 64x64 matrix, for which I have all the values, I will just need to copy and paste them from a file. The point is that the numbers are like in the above example. That said, imaginary parts end with 'j', some numbers have only real part, and some just imaginary part, and of course some both the real and imaginary parts. Therefore, I want to ask if I enter the values to my Complex matrix like in the above example, will everything be okay? I mean it will know which part is imaginary, which part real? And what will happen when the numbers don't have either their real or imaginary parts?

This post has been edited by erkant: 17 July 2012 - 06:29 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Complex structure question

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5777
  • View blog
  • Posts: 12,591
  • Joined: 16-October 07

Re: Complex structure question

Posted 17 July 2012 - 06:41 AM

First off, j is meaingless to your code. Just having something like 31356j isn't going to work.

Given your struct, you'd declare your matrix like so:
Complex matrix[2][3] = {
	{ {9511, 31356}, {12539, 30273}, {-32610 , -3211} },
	{ {32767, 0}, {0, -32768}, {6392, 32138} },
	};


Was This Post Helpful? 2
  • +
  • -

#3 erkant  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 108
  • Joined: 26-October 10

Re: Complex structure question

Posted 17 July 2012 - 11:25 AM

Thanks baavgai!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1