Fibonacci Times (Iter vs Recursive) Log Log Plot

조회 수: 5 (최근 30일)
SB
SB 2012년 11월 9일
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
SB
SB 2012년 11월 9일
Thanks for the input, I've adjusted accordingly.
Walter Roberson
Walter Roberson 2012년 11월 9일
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.)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Networks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by