I have to write a recursive function in python that generalizes the following function:
f(n) result
0 1
1 1
2 2
3 5
4 13
5 34
6 89
7 233
I made something like this:
def F(n):
if n <= 0:
return 1
else:
return 2*( F(n-1) + F(n-2) ) - F(n-3)
It works with almost all values of the range but it doesn't match with the 3 first results so. How can I determine a recursive function based on the outputs?
I have this information:
"Hint: F(n) is recursively defined in terms of F(n-1) and F(n-2). You have to figure out the math expression that will make this happen. Hint: no coefficient of the function in this expression is greater than 5, nor less than 1, and any such coefficient is an integer."
F(n)is defined as exactlya*F(n-1) + b*F(n-2), where the exercise is to determine whataandbare?2*F(n-1) + 2*F(n-2) - F(n-3)?F(n-1)andF(n-2). Are these the only terms you are expected to use?