Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
question on fibonacci sequence.?
max=20
n=zeros(max,1);
n(1)=0;
n(2)=1;
for i=3:max
n(i)=n(i)+n(i-1)+n(i-2)
end
why does we need to write n=zeros(max,1); what does this means?
and please explain how to get this n(i)=n(i)+n(i-1)+n(i-2)?
thanks much.
1 Answer
- peteamsLv 71 decade ago
I assume zeros(max,1) creates an array of max items, the 1 being the number of dimensions. I suppose it could create an array of max 1s, but then why would they call the function zeros.
The n(i)=n(i)+n(i-1)+n(i-2) looks like a programming error. n(i) by either definition of zeros will be a known constant, so it makes no sense. I imagine they intended to write n(i)=n(i-1)+n(i-2).