SKM
SKM

Reputation: 989

Matlab : Multiplication using complex numbers - what is the proper operator?

I am trying to compute the expression (z*(z-h*a))^2 using complex valued data. This expression works fine when the inputs are real valued. I should get a scalar. But, using complex valued input I am getting a vector. What is the proper operator for complex number multiplication?

z = -6.1 -6.55i;
a = 7.0000 - 7.0000i;
 h = [-0.1340 - 1.0315i,  -0.2770 - 1.0810i,   0.7774 - 0.5708i];

temp = 0.0;
temp =  (z*(z-h*a)).^2;

Upvotes: 0

Views: 101

Answers (1)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38042

For vector-valued input h, that equation will result in a vector, regardless of whether the numbers involved are real, complex, octonion, or what not (provided you do element-wise squaring, .^2).

Troy is right - you need the sum of the squares:

z = -6.1 - 6.55i;
a = 7.0000 - 7.0000i;
h = [-0.1340 - 1.0315i,  -0.2770 - 1.0810i,   0.7774 - 0.5708i];

temp = z * (z - h*a);
temp = temp * temp.';

Upvotes: 2

Related Questions