quick calculation in one second
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Walter Roberson
2016년 3월 14일
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
Walter Roberson
2016년 3월 14일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!