这段代码运行时间非常长(超过10分钟),有没有什么方法可以进行优化,使得它在不到一分钟内完成?
clear all;
for i = 1:1000000
harmonicsum = 0;
lhs = 0;
for j = 1:i
% compute harmonic sum
harmonicsum = harmonicsum + 1/j;
% find sum of factors
if (mod(i,j)==0)
lhs = lhs + j;
end
end
%define right hand side (rhs) of Riemann Hypothesis
rhs = harmonicsum + log(harmonicsum) * exp(harmonicsum);
if lhs > rhs
disp('Hypothesis violated')
end
end
j
作为因数”,这要容易得多。 - Ben Voigt