【发布时间】:2016-07-08 18:04:48
【问题描述】:
在 Octave 4.0.0 和 MATLAB 2014 中都运行了以下代码。时间差很愚蠢,即超过两个数量级。在 Windows 笔记本电脑上运行。可以做些什么来提高 Octave 的计算速度?
startTime = cputime;
iter = 1; % iter is the current iteration of the loop
itSum = 0; % itSum is the sum of the iterations
stopCrit = sqrt(275); % stopCrit is the stopping criteria for the while loop
while itSum < stopCrit
itSum = itSum + 1/iter;
iter = iter + 1;
if iter > 1e7, break, end
end
iter-1
totTime = cputime - startTime
八度:totTime ~ 112
MATLAB:totTime
【问题讨论】:
-
我不知道您是否注意到您的函数计算谐波系列的总和。因此,如果您有很多迭代,您最好使用 sum(1./(1:exp(stopCrit)) 例如,然后调整总和,直到 sum(1./(1:#iteration)) = stopCrit。
标签: performance matlab octave computation