答案 0 :(得分:0)
using element-wise .* operations will be dramatically faster than 4 nested for loops. I think you want something like this:
M = 100;
K = 100;
N = 40;
x = linspace(0,1,N);
y = linspace(0,1,N);
%order reversed matches i,j notation in question
[Y,X] = meshgrid(y,x);
A = zeros(size(X));
for m = 1:M
for k = 1:K
A = A + sqrt(m^2 + k^2)*sin(m*X).*cos(k*Y);
end
end