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
But I've heard, that on big arrays matlab "freezes" on nested loops-> Where have you heard this? MATLAB does fine with big loops, but they're not always necessary. It's often easier to get something working with loops first, otherwise you're doing premature optimisation at the expense of having a minimal reproducible example. Do you have something which works with a loop? Is it too slow? You could show us that, presumably it's not too slow for some small input...