フィルターのクリア

Fibonacci Times (Iter vs Recursive) Log Log Plot

2 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by