Fibonacci Times (Iter vs Recursive) Log Log Plot
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to graph one log-log plot of the execution time
against increasing input values for an iterative fibonacci sequence solution
and a recursive fibonacci sequence solution, two functions I made to show the
fibonacci sequence, and I'm not sure if I'm doing it right. I have a graph
showing up, but I don't know if my code is correct for it. I know that my
fib_iter and fib_recur work, so that shouldn't be an issue. Here's what I have
at the moment:
%
function fib_plot()
n_rec = 10:25; t_rec = zeros(size(n_rec));
for i = 1:length(n_rec)
n = n_rec(i);
tic; fib_recur(n); t_rec(i) = toc;
end
n_iter = 1000:1000:100000; t_iter = [];
for n = n_iter
tic; fib_iter(n); ti = toc;
t_iter = [t_iter ti];
end
loglog(n_rec,t_rec,n_iter,t_iter);
xlabel('log N'), ylabel('log Time');
legend('recursion','iteration');
Please let me know if I'm doing this correctly- my image is below:
4 commentaires
Walter Roberson
le 9 Nov 2012
Looks plausible, taking into account that you are using very different ranges for the testing (which would probably not be expected, so you might want to consider including 1:999 in your iterated test.)
Réponses (0)
Voir également
Catégories
En savoir plus sur Annotations 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!