quick calculation in one second

조회 수: 2 (최근 30일)
Hao Zhang
Hao Zhang 2016년 3월 13일
댓글: Walter Roberson 2016년 3월 14일
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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 3월 14일
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
Hao Zhang
Hao Zhang 2016년 3월 14일
Yes, even it is in a parallel environment, it does not work as we expected. indeed, it can be done within one second. Calculation in a vector or matrix form , not using for loop, may be a possible way, i think.
Walter Roberson
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 CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by