MATLAB: Can someone do this calculation without for loops

matrix manipulation

a = [1 2 3; 4 5 6];
b = [ 1 2 3 4];
c = [1 2 3 4 5];
for n = 1: size(a,1)
for m = 1:size(a,2)
for s = 1: length(b)
for k = 1: length(c)
L(n,m,s,k)= a(n,m) +b(s)*a(n,m)*exp(c(k)*a(n,m));
end
end
end
end

Best Answer

tmp = bsxfun(@times,a,reshape(c,1,1,1,[]));
tmp = bsxfun(@times,a,exp(tmp));
tmp = bsxfun(@times,reshape(b,1,1,[]),tmp);
tmp = bsxfun(@plus,a,tmp);
Note that the floating point error propagates slightly differently, so isequal will be false.