Search code examples
cmultiplication

How to multiply a complex number(complex integer) with an integer in C?


I have an array of size 10 which has values from 0 to 4 as real parts (integers) and from 5 to 9 as imaginary parts (integers) from a file which had 5 complex no.'s (I created a new array of twice the size to hold real and imaginary parts from the original complex stream). I have to multiply them with another array of integers (non-complex), how do I go about it?

for illustration

complex_file = 2 + 5j, 1 + 6j, 3 + 7j;
new_array = 2,1,3,5,6,7 (first 3 as real parts, the next 3 as imag ones)
mult_coeff = 11,12,13 (diff integer array which needs to be multiplied with the complex values)

Here's the catch, output needs to be represented as complex.


Solution

  • A complex value multiplied by a strictly real value changes the magnitude but not the phase angle of the complex value. Thus you can multiply the components (real part and “imaginary” part) of the complex values separately by the real value since there are no cross products that would result in a change of phase angle.

    So if you consider the format of your input to be a complex data type, the multiplied output will be similarly complex, after multiplying all the components by a strictly real scale factor. If not, you can shuffle or repack the components into whatever resulting complex vector format or data type you require.