I have an equation to count, that looks like this:
F(a,b) = sum(c=1...n, a*b*c[i])
I can count it this way:
for a=
for b=
for c=
F(a,b)=F(a,b)+a*b*c
end
end
end
But I've heard, that on big arrays matlab "freezes" on nested loops. So I can do it this way:
a=(1:n)';
b=1:n2;
Fs=a*b;
for c=
F=F+Fs*c;
end
But I want to solve this problem without any visible cycle. So I can create three orthogonal arrays of a,b,c tensor product them to get 3-D array, and then use sum function by third dimension.
a(:,1,1)=1:3;
b(1,:,1)=4:6;
c(1,1,:)=7:9;
d=tensorprod (a,b,2,1)
e=tensorprod (d,c);
But I ran into tensor multiplication problem in matlab. e has to be 3x3x3 array, but it is 3x3x1x1x3 array. It is correct and all, and even
g=sum(e,5);
returns matrix, but I don't understand why the third dimension has moved to the fifth