Plotting simple algorithm, problem with axis

1 回表示 (過去 30 日間)
MiauMiau
MiauMiau 2013 年 2 月 21 日
Hi
Below my algorithm: First I store the so called Lucas Numbers in a vector v. v contains the N first lucasnumbers. Then I calculate the ratio of the two consequent lucas numbers, i.e. w(1) = v(2)/v(1) etc. and store these results in a vector w with length N-1.
What I want to do next then, is to calculate the absolute value between a defined constant phi and the elements of w and plot them as a function of N-1. But when I try to do so, for the x-axis I never get the range 1:N-1. Why is that?
function plotLucas(N)
% initialize vector v
% v contains the Lucas Numbers
v = zeros(N,1)
v(1) = 1;
v(2) = 3;
for i = 3:size(v,1)
v(i) = v(i-1)+v(i-2)
end
% initialize vector w
% w contains the quotients
w = zeros(N-1,1)
for i = 1:size(w,1)
w(i) = v(i+1)/v(i);
end
phiLucas = (1+sqrt(5))/2
y = abs(w-phiLucas)
plot(y, 1:N-1)
end
Thanks
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 21 日
How did you check that?
José-Luis
José-Luis 2013 年 2 月 21 日
plot(y, 1:N-1)

サインインしてコメントする。

採用された回答

Thorsten
Thorsten 2013 年 2 月 21 日
Reverse the arguments of plot(x,y)
plot(1:N-1, y)
  2 件のコメント
MiauMiau
MiauMiau 2013 年 2 月 21 日
you are right, what a stupid mistake..thanks
Thorsten
Thorsten 2013 年 2 月 21 日
If this answered your question, would you please be so kind to accept this answer?

サインインしてコメントする。

その他の回答 (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