Borrar filtros
Borrar filtros

Fibonacci Times (Iter vs Recursive) Log Log Plot

2 visualizaciones (últimos 30 días)
SB
SB el 9 de Nov. de 2012
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 comentarios
SB
SB el 9 de Nov. de 2012
Thanks for the input, I've adjusted accordingly.
Walter Roberson
Walter Roberson el 9 de Nov. de 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.)

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by