I am looking for a way to vectorize a combined matrix multiplication and element-wise addition.
Let's say I have a matrix function M_{ij}(x), and a vector function v_j(x), where {i,j} are matrix indices, and x is a position variable. I want to perform an element-wise matrix multiplication and find u(x) = M(x).v(x). A straightforward example is:
imax = 2; jmax = 3; xmax = 10;
M=rand(imax,jmax,xmax);
v=rand(jmax,xmax);
u=zeros(imax,xmax);
for i=1:imax
for j=1:jmax
u(i,:) = u(i,:) + squeeze(M(i,j,:))'.*v(j,:);
end
end
Is there a vectorized way to speed up this operation? In my problem we will assume that imax,jmax are <5, and that xmax is large.