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

2 vues (au cours des 30 derniers jours)
ime sem
ime sem le 16 Jan 2014
Commenté : Walter Roberson le 21 Jan 2014
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;

Réponses (1)

Walter Roberson
Walter Roberson le 16 Jan 2014
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.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by