Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C# - task 3 A complex number C consists of two parts, one real and one imaginary

ID: 3710914 • Letter: C

Question

C# - task 3

A complex number C consists of two parts, one real and one imaginary. It can be written as follows:

C = Cr + j · Cj, where Cr and Cj are real numbers and j is the imaginary number ?-1

Here the Cr is the real part and j · Cj the imaginary part of the complex number C.

A multiplication between two complex numbers follows common rules for multiplication of two two-element factors (remember that j2 = -1):

A · B = (Ar + jAj) · (Br + jBj) = (Ar · Br - Aj · Bj) + j (Ar · Bj + Aj · Br) = Cr + jCj = C

Define a method that can multiply two complex numbers according to the formula above. Use the void as the function's return data type, the components of the complex numbers A and B as "input" parameters, and the components of the result, the complex number C, as "out" parameters (ie, reference transfer values).

Test the function with a program that presents the calculation and results, as these examples show:

                    (1 + 2j) * (3 -4j) = 11 + 2j

                    (20 -10j) * (-2 -4j) = -80-60j

For reasons sake: The order of the factors is indifferent, so that A · B = B · A.

Explanation / Answer

void complex_multiply(float ar, float aj, float br, float bj, float *cr, float *cj)
{
    *cr = ar * br - aj * bj;
    *cj = ar * bj + aj * br;
    return;
}