Apple Bing Google Tahoo The Fibonacci Sequence and the Golden Ratio Believe it o
ID: 3732625 • Letter: A
Question
Apple Bing Google Tahoo The Fibonacci Sequence and the Golden Ratio Believe it or not, the golden ratio has been used to predict trends in the stock market and for other applications in financial analysis. The golden ratio and the Fibonacci sequence are related, and both seem to reflect a basic law of nature which you can read about here. The relationship is given by lim Fn+1) where F(n) is the nth term in the Fibonacci sequence and o is the golden ratio given by For large values of n, you can find the approximate value of the next term in the Fibonacci sequence by multiplying the current term by the golden ratio. You may recall that the exact Fibonacci sequence is obtained by adding two successive terms to get the next term: 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 .. i.., 1+1 2,1+2-3, 2 + 3 5,and so on. The Fibonacci spiral shown hereExplanation / Answer
def recur_fibo(n):
"""Recursive function to
print Fibonacci sequence"""
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
def standard_deviation(lst, population=True):
"""Calculates the standard deviation for a list of numbers."""
num_items = len(lst)
mean = sum(lst) / num_items
differences = [x - mean for x in lst]
sq_differences = [d ** 2 for d in differences]
ssd = sum(sq_differences)
# Note: it would be better to return a value and then print it outside
# the function, but this is just a quick way to print out the values along
# the way.
if population is True:
print('This is POPULATION standard deviation.')
variance = ssd / num_items
else:
print('This is SAMPLE standard deviation.')
variance = ssd / (num_items - 1)
sd = sqrt(variance)
# You could `return sd` here.
print('The mean of {} is {}.'.format(lst, mean))
print('The differences are {}.'.format(differences))
print('The sum of squared differences is {}.'.format(ssd))
print('The variance is {}.'.format(variance))
print('The standard deviation is {}.'.format(sd))
print('--------------------------')
# Change this value for a different result
nterms = input("Please enter an integer number")
print nterms
# uncomment to take input from the user
#nterms = int(input("How many terms? "))
# check if the number of terms is valid
for val in range(nterms):
#print val
#if val <= 0:
# print("Plese enter a positive integer")
#else:
print("Fibonacci sequence:")
shopList = []
for i in range(val):
value = recur_fibo(i)
shopList.append(value)
#print shopList
print(recur_fibo(i))
standard_deviation(shopList)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.