Bob.may.py: USE PYTHON print(\"The one point iteration that brought chaos into f
ID: 3673018 • Letter: B
Question
Bob.may.py: USE PYTHON
print("The one point iteration that brought chaos into focus!")
print('Try these values of r: 3, 3.5, 3.544099, 3.56445, 3.568759')
r=float(input('Enter the value of r = '))
N=10000
x=[0 for i in range(0, N)]
x[0]=0.7
index=[0 for i in range(0, N)]
#=============================================
# Main iteration
#=============================================
for n in range(1,N):
index[n]=n
x[n]=r*x[n-1]*(1-x[n-1])
# Let us print the last 100 values
print('The last 4 values are:')
print(x[N-4], ' , ',x[N-3],' , ', x[N-2], ' , ', x[N-1])
#=============================================
# Plotting
import matplotlib.pyplot as plt
plt.plot(index[N-100:N], x[N-100:N])
plt.show()
#=============================================
Explanation / Answer
while True:
print("The one point iteration that brought chaos into focus!")
print('Try these values of r: 3, 3.5, 3.544099, 3.56445, 3.568759')
r=input('Enter the value of r = ')
try:
if r!="done":
r=float(r)
N=10000
x=[0 for i in range(0, N)]
x[0]=0.7
index=[0 for i in range(0, N)]
#=============================================
# Main iteration
#=============================================
for n in range(1,N):
index[n]=n
x[n]=r*x[n-1]*(1-x[n-1])
# Let us print the last 100 values
print('The last 4 values are:')
print(x[N-4], ' , ',x[N-3],' , ', x[N-2], ' , ', x[N-1])
#=============================================
# Plotting
import matplotlib.pyplot as plt
plt.plot(index[N-100:N], x[N-100:N])
plt.show()
continue
#=============================================
else
break
except:
print("If you are finished enter : done, else enter number.")
continue