pythonchaos

Creating a bifurcation diagram in python


I am trying to come up with a code that will allow me to plot a diagram for period doubling bifurcation.

I am using the equation x = rx − 1(1 − x), and am trying to model it with r values from 0.5 to 4. Here is code that I am working with

startr = 0.5
finalr = 4
max_time = 200
x = [0.1]
r= np.linspace(.5,4,200)

for n in range(0,200):

    x = np.append(r * x[n] * (1-x[n]))


plt.plot(x, label='x');
plt.xlabel('t');

This keeps getting kicked out

TypeError: append() missing 1 required positional argument: 'values'

Solution

  • The are the two absolutely necessary arguments for numpy.append(), taken from the Numpy reference.

    arr : array_like Values are appended to a copy of this array.

    values : array_like These values are appended to a copy of arr. It must be of the correct shape (the same shape as arr, excluding axis). If axis is not specified, values can be any shape and will be flattened before use.

    Therefore, try using

    np.append(x, r * x[n] * (1-x[n]))
    

    inside your loop.