필터 지우기
필터 지우기

can you help me to ploting the number of operations we use flops

조회 수: 1 (최근 30일)
ime sem
ime sem 2014년 1월 16일
댓글: Walter Roberson 2014년 1월 21일
function pgd = pgdd(~)
n=1000;
i = 2;
while i<= sqrt(n) && mod(n,i)~=0
i = i+1;
end
if mod(n,i)~=0
pgd = mod(n,i);
else
pgd = n;
end
flops pgdd;
end
plot;

답변 (1개)

Walter Roberson
Walter Roberson 2014년 1월 16일
No, the flops() analyzer of MATLAB is obsolete and was never really accurate. There is no replacement that works on modern processors as modern processors perform multiple floating point operations simultaneously.
You should also be paying attention to the fact that you are repeating mod(n,i) up to three times and expecting the same answer in each of them. Does that reflect actual flops of the algorithm, or does that reflect inefficient coding? You can assign the result of the mod() to a variable and test and return the variable instead of recalculating the mod. Likewise you do not need to sqrt(n) each iteration: you can do the calculation once and assign the result to a variable, saving yourself a floating point operation per loop.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by