datcn
datcn

Reputation: 751

Confusions about Multiplication of Complex Value in MatLab

I noticed a confused computation of complex valued multiplication in Matlab. One simple example is as below:

syms x1 x2 x3 x4
s=[x1 x2]*[x3 x4]'

And the return value of s is like:

s=x1*conj(x3) + x2*conj(x4)

In my opinion s should be equal to x1*x3+x2*x4. So, what's the problem here?

Then, how should I do if I want to get a multiplication of two complex vector?

update: I find out it will be solved through using .' rather than . like:

s=[x1 x2]*[x3 x4]

Upvotes: 0

Views: 4844

Answers (3)

Drodbar
Drodbar

Reputation: 537

The operator ' is the also called Complex conjugate transpose in Matlab ctranspose, which basically means that it applies conj and and transpose functions. Note that this operator is call Hermitian operator in mathematics.

What you actually want is the operator transpose that is shortcut as .'

In order to get the expected output, and given that you just want to multiply without conjugating the second vector, you should do:

>> syms x1 x2 x3 x4
>> s = [x1 x2]*[x3 x4].'

so your output will be:

x1*x3 + x2*x4

For further information you can check help ., to see the list of operators, help transpose and help ctranspose

Upvotes: 4

tmpearce
tmpearce

Reputation: 12693

Maybe this will help explain:

>> syms x1 x2 x3 x4
>> s=[x1 x2]*[x3 x4]'
s =
x1*conj(x3) + x2*conj(x4)

>> s=[x1 x2]*[x3; x4]
s =
x1*x3 + x2*x4

>> [x3 x4]'

ans =

 conj(x3)
 conj(x4)

The ' version of transpose isn't doing what you want. Use transpose instead:

>> transpose([x3 x4])
 ans =
 x3
 x4

Upvotes: 1

Chris Taylor
Chris Taylor

Reputation: 47392

Note that the ' operator in Matlab is the conjugate transpose, i.e. it both transposes a matrix and takes the complex conjugate:

>> (1+1i)'
ans =
   1.0000 - 1.0000i

If you want the matrix transpose then you should use the .' operator:

>> (1+1i).'
ans =
   1.0000 + 1.0000i

Upvotes: 2

Related Questions