I have following matrices :
X=1 2 3
Y=4 5 6
A=1 2 3
4 5 6
7 8 9
I Want to do
for each (i,j) in A
v = A(i,j)*X - Y
B(i,j) = v * v'
i.e. each element of A is multiplied by vector X, then resultant vector subtracts Y from itself and finally we take inner product of that vector to bring a single number.
Can it be done without for loop ?
One thing often forgotten in Matlab: The operator
'
takes the conjugate transposed (.'
is the ordinary transposed). In other words,A' == conj(trans(A))
, whereasA.' == trans(A)
, which makes a difference ifA
is a complex matrix.Ok, let's apply some mathematics to your equations. We have
So a first result would be
In the case of real matrices/vectors, one has the identities
which means, you can reduce the expression to
An alternative method:
I get the result: