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

1 次查看(过去 30 天)
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 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by