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;
0 个评论
回答(1 个)
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!