Array of Complex number.

greetings to all.

I am working with complex numbers in arduino. I want to know that how to make an array of complex numbers in arduino. Secondly how to convert complex numbers to any other data type like double or float?

It is easily done with structs. But my worry would have been how to do complex number calculations. You should be looking for an existing library for this. No doubt, it has been done many times.

  1. Two arrays, one for the real portion and one for the imaginary portion.
  2. Good luck. Complex numbers have two parts. There is no way to represent one as a single number. The best you can do is turn it into a vector which itself is two numbers - an angle and a magnitude.

JoeN:

  1. Two arrays, one for the real portion and one for the imaginary portion.

No. Just no.

typedef struct { float real; float imaginary;} complex_t;
 complex_t my_complex_arrray[5] = {
  {1.0, 1.0},
  {PI, 1.0},
  {1.0, 0}, // 1.0 real
  {0, 1.0}, // j imaginary
  {0, 0}
 };

aarg is right, though; this has probably been implemented many times. Though I don't know offhand whether there's a version aimed at the limitations of the embedded world...

thanks all for reply,,,

I have done calculations with complex numbers and i am using the libarary "complex.h". I just want now to make an array of 1x6 in which i could store 6 complex numbers...

Complex class - Complex numbers library - Libraries - Arduino Forum -

updated the Complex class with an array example: V0.1.09

I have done calculations with complex numbers

Which you are representing how?

An array of that same type is trivial.

Nice, @robtillart. It's a classic example of the power of OO in C++, with the ability to easily extend the language with operator overloading.

thanks @robtillart. Now my problem has solved.......

Does Arduino/AVR/gcc support C 1999? It includes complex types.

Does Arduino/AVR/gcc support C 1999? It includes complex types.

It looks like it's in the compiler, but not in avr-libc.
"float _Complex a;" is accepted, but there is no "complex.h" (and none of the cxxx() math functions, either.)