2017-02-17 88 views
1

我想要一個代碼,它允許我繪製一個雙倍分叉期間的圖。在python中創建一個分叉圖

我使用的公式x = rx − 1(1 − x),並正嘗試將其與的R值模型0.5〜4。這裏是我與

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'); 

工作代碼此狀態越來越踢出

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

回答

1

的是numpy.append()兩個絕對必要的參數,從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.

01所

因此,嘗試使用

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

你的循環中。

+0

謝謝!它在那條確切的線上給我一個新的錯誤-IndexError:對標量變量無效的索引。 –

+0

我沒有收到錯誤信息,當我在執行修復程序時運行代碼時。也許你可能需要更新一段代碼來問一個新問題,以解決你在代碼中遇到的新問題 – nikaltipar