In the Fibonacci sequence, is fib(0) 0 or 1 ?

前端 未结 10 1781
南旧
南旧 2020-12-14 15:11

I\'m doing a task in a subject were fib(0) is defined to = 1. But that can\'t be right? fib(0) is 0?

Program with fib(0) = 1; spits out fib(4) = 5
Program w         


        
相关标签:
10条回答
  • 2020-12-14 15:28

    You cannot have zero rabbits and thus produce a pair, and "how many pairs of rabbits can be produced in a year starting with one pair and reproducing monthly starting with the second month" was the original question to Fibonacci.

    0 讨论(0)
  • 2020-12-14 15:32

    Fibonacci series doesn't start with 0. It starts with 1.
    We are getting confused trying to represent a mathematical concept as a computer program. The term "Fib(0)" is the array index that holds the first Fibonacci number which is always 1. We are asking this question because we have to return something from the program when someone enters 0 as input. What that input essentially means is to generate 0 Fibonacci numbers. So you return a message saying "No Fibonacci numbers generated"

    0 讨论(0)
  • 2020-12-14 15:38

    Based on the definition of the Fibonacci sequence, you can generate a closed form for defining the nth element:

    F(n) = ( f^n - (1-f)^n ) / sqrt(5),
    where f = (1 + sqrt(5)) / 2 [the golden ratio]
    

    For n = 0 it is clearly 0:

    F(0) = (1 - 1) / sqrt(5) = 0.
    
    0 讨论(0)
  • 2020-12-14 15:39
    fib 0 = 0
    fib 1 = 1
    

    That is the seed value definition.

    0 讨论(0)
  • 2020-12-14 15:40

    You're correct. The Fibonacci sequence is formally defined with seed values fib(0) = 0 and fib(1) = 1. This is a requirement for the rest of the sequence to be right (and not offset by one or anything).

    In mathematics, the Fibonacci numbers, commonly denoted F_n, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1.

    In mathematics, the Fibonacci numbers, commonly denoted Fn, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1.

    Edit: I have to concede that there is another (much less common, and usually informal) way to define the sequence by seeding it with values 1 and 1, but this is not the conventional one by any means. It is certainly not preferred in all the formal mathematical definitions I’ve seen, like The On-Line Encyclopaedia of Integer Sequences.

    0 讨论(0)
  • 2020-12-14 15:43

    They are both correct. If you specify a sequence G{n} by the recursion G{1} = 3, G{2} = 5, G{n} = G{ n - 1} + G{ n - 2} then most people would agree that is "a Fibonacci sequence". The only difference being a few terms at the front, but the leading terms are mostly irrelevant for any interesting questions about the sequence. The heart of a Fibonacci sequence is the addition rule, and any sequence that uses that rule is a Fibonacci sequence. It is only necessary to specify whether 0 is in the sequence if you want to ask specific questions about a particular index... every thing else is just a translation on the index and is pretty much irrelevant. That is, if the problem is 'find a closed form solution for the Nth value in the sequence', then solving it for G will solve the problem for F with just a trivial shift of the solution. The hard part of the problem is the same for both sequences.

    0 讨论(0)
提交回复
热议问题