Fibonacci Times (Iter vs Recursive) Log Log Plot

1 view (last 30 days)
SB
SB on 9 Nov 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 Comments
SB
SB on 9 Nov 2012
Thanks for the input, I've adjusted accordingly.
Walter Roberson
Walter Roberson on 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.)

Sign in to comment.

Answers (0)

Categories

Find more on Networks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!