【发布时间】:2021-10-25 15:20:11
【问题描述】:
我有一个函数 f(x,y) = abs(cos(x+3) * sin(y+2)),我需要使用两个 for 循环对其进行总结。注意:真正的功能更复杂,这是一个玩具版本的问题。
f = @(x,y) abs(cos(x+3) * sin(y+2));
tot = 0;
for m=1:100
for n=1:100
tot = tot + f(m,n);
end
end
disp(tot)
Output: 4.026314876227891e+03
如何对这段代码进行矢量化以摆脱 for 循环并使其更快?
【问题讨论】:
标签: matlab vectorization