1

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'
lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228

2 Answers2

1

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.

codingEnthusiast
  • 3,800
  • 2
  • 25
  • 37
  • thanks! It's giving me a new error at that exact line -IndexError: invalid index to scalar variable. – Amanda Jacqualyn Feb 20 '17 at 00:57
  • I am not getting an error, when I run your code with my fix implemented. Perhaps you might have to ask a new question with your updated piece of code in order to address the new issue that you are having with your code – codingEnthusiast Feb 21 '17 at 00:37
0

Logistic Map Save file and run, png image file of graph will save in the same folder

import numpy as np
import matplotlib.pyplot as plt

Many =50000

x = np.random.rand(Many)
r = np.linspace(0,4.0, num= Many)

for i in range(1, 54):
    x_a = 1-x
    Data= np.multiply(x,r)
    Data= np.multiply(Data, x_a)
    x = Data

    plt.title(r'Logistic map: $x_{n+1} = r x_{n} (1-x_{n}).$  n = '+ str(i) )
    plt.ylabel('x-Random number')
    plt.xlabel('r-Rate')
    
    plt.scatter(r, Data, s=0.1, c='k')
    plt.show()
    plt.savefig(str(i) + " Logistic Map.png", dpi = 300)
    plt.clf()