quick calculation in one second
1 view (last 30 days)
Show older comments
Hello, if there is a sequence x(i) (more than 1 million number points), how to optimize the algorithm and calculate the equation below in about one second? Thanks!
N = length(x);
J=[1 2 4 10 20 40 100 200 400 1000 2000 4000 10000 20000 40000 100000 200000 400000 1000000];
for h=1:1:19
q = J(h);
if (q<=N/3)
p(1:1:N-3*q+1)=0;
for j=1:1:(N-3*q+1)
p(j)=sum(x(j+2*q:1:j+3*q-1))-2*sum(x(j+q:1:j+2*q-1))+sum(x(j:1:j+q-1));
end
time(h)=q;
Stability(h) = sqrt(sum(p.*p)/(6*q*q*(N-3*q+1)));
end
end
0 Comments
Answers (1)
Walter Roberson
on 14 Mar 2016
This appears to be the same equation as your previous question http://www.mathworks.com/matlabcentral/answers/270756-quick-numerical-calculation-without-for-loop
Florian was able to suggest a method there that took about 11 seconds in a parallel environment. Are you running a parallel environment?
Do you have a reason to expect that your formula can be calculated in about 1 second on whatever machine you are using?
2 Comments
Walter Roberson
on 14 Mar 2016
You will not be able to evaluate that within 1 second by executing that formula in a straight-forward way. Each term is summed multiple times, with the overall number of summations on the order of magnitude of 6*m^2
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!