我的家庭作業讓我寫一個代碼,模擬泰勒教科書在經典力學中的數字。如果有人有興趣知道,請撥打和。分岔圖沒有繪圖/劇情只是沒有出現
我能夠重現他們中的一個是下面的代碼(這可能是我確實遇到問題的代碼很好的參考):
import nympy as np
import matplotlib.pyplot as plt
# We need to calculate the first fixed point
r1=np.array(np.arange(0,4,0.09))
x1 = np.zeros((len(r1),1))
# Now calculating the second fixed point
r2=np.array(np.arange(1,4,0.1))
x2 = (r2 -1)/r2
# Now finding when the fixed points split up again
r3=np.array(np.arange(3,4,0.1))
y1 = (((r3**2 - 2*r3 - 3)**0.5) + 1 + r3)/(2*r3)
y2 = ((-(r3**2 - 2*r3 - 3)**0.5) + 1 + r3)/(2*r3)
# Now finding the experimental values for 1/2 of a split
x3 = []
for r in np.arange(0,4,0.09):
x = 0.666
for i in range(100):
x = (r**2) * x * (1.0 -x) - (r**3) * (x**2)*((1-x)**2)
x3.append(x)
# Doing the same as above second 1/2
x4 = []
for r in np.arange(0,4,0.09):
x = 0.8
for i in range(100):
x = (r**2) * x * (1.0 -x) - (r**3) * (x**2)*((1-x)**2)
x4.append(x)
plt.plot(r1,x3,'bo', label='Experimental')
plt.plot(r1,x4,'bo')
plt.plot(r3,y2,'k-')
plt.plot(r3,y1,'k-')
plt.plot(r1,x1,'k-', label='Theoretical')
plt.plot(r2,x2,'k-')
plt.legend(loc=2)
plt.show()
,這裏是第二圖像的代碼這似乎並不奏效。我不知道爲什麼。任何幫助,將不勝感激。這個數字只是沒有繪製,我不知道爲什麼。
import numpy as np
import matplotlib.pyplot as plt
for r in n.arange(2.8,4,0.01):
x = 0.5
for i in range(150):
x = r*x*(1-x)
if i >= 125:
plt.plot(r,x,'k')
plt.xlim (2.8,4)
plt.show()
歡迎所以堆棧溢出。請閱讀[如何提出一個好問題](http://stackoverflow.com/help/how-to-ask)。另外,請粘貼您的代碼,而不是插入圖片。在帖子中有一個「{}」按鈕,可以將所有內容縮進四個空格,並顯示爲代碼 –
您是否在使用IPython筆記本? – Xevaquor