can you help me to ploting the number of operations we use flops
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 16 de En. de 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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!