This is a very basic question and I would appreciate any help. I've written code to calculate the Fibonacci sequence using a “for” loop. I want to display the elements of the sequence whose indices are specified in the array “N”. The problem is that all displayed values are the same as the value associated with the first element of “N”.
N=[10 100 1000];first=1;second=1;for i=1:(N-2) %The index has to have two terms removed because it starts with 1 and 1 already
next=first+second; %The current term in the series is a summation of the previous two terms
first=second; %Each term must by iterated upwards by an index of one
second=next; %The term that previously was second is now referred to as next
endfor i=1:length(N) disp([N(i) next])end
Thanks
Best Answer