## Multiply each column of a matrix by another matrix

on 9 Apr 2019
Latest activity Commented on by Miguel Morgado

on 10 Apr 2019

### James Tursa (view profile)

Hi,
I have 2 matrices, E of dimension 4x57 and J of dimension 4x4.
I'm trying to do the operation C = sqrt(E'*J*E) for each column of E, so that C ends up being a vector of length 57.
Any ideas of how to do this without a loop?
Thank you very much

#### 1 Comment

on 9 Apr 2019
E'*J*E
will result in a 57x57 matrix so what is the operation you are actually trying to achieve in ordder to get a length 57 vector?

R2018b

### James Tursa (view profile)

on 9 Apr 2019
Edited by James Tursa

### James Tursa (view profile)

on 9 Apr 2019

Another way:
C = sqrt(sum(E.*(J*E)));
For the sizes involved, you probably won't see any significant timing differences between this method and Johathan's method. For much larger sizes, this method does less overall calculations than Jonathan's method and may run faster as a result.

#### 1 Comment

on 10 Apr 2019
Worked perfectly, thank you very much