【发布时间】:2017-04-01 21:19:26
【问题描述】:
我尝试绘制具有边界条件的一维空间扩展系统的分岔图
x[i,n+1] = (1-eps)*(r*x[i,n]*(1-x[i,n])) + 0.5*eps*( r*x[i-1,n]*(1-x[i-1,n]) + r*x[i+1,n]*(1-x[i+1,n])) + p
我在获得所需的输出数字时遇到问题可能是因为我使用的瞬态数量。有人可以通过交叉检查我的代码来帮助我吗?我应该选择哪些 nTransients 值或应该忽略多少瞬变?
我的Python代码如下:
import numpy as np
from numpy import *
from pylab import *
L = 60 # no. of lattice sites
eps = 0.6 # diffusive coupling strength
r = 4.0 # control parameter r
np.random.seed(1010)
ic = np.random.uniform(0.1, 0.9, L) # random initial condition betn. (0,1)
nTransients = 900 # The iterates we'll throw away
nIterates = 1000 # This sets how much the attractor is filled in
nSteps = 400 # This sets how dense the bifurcation diagram will be
pLow = -0.4
pHigh = 0.0
pInc = (pHigh-pLow)/float(nSteps)
def LM(p, x):
x_new = []
for i in range(L):
if i==0:
x_new.append((1-eps)*(r*x[i]*(1-x[i])) + 0.5*eps*(r*x[L-1]*(1-x[L-1]) + r*x[i+1]*(1-x[i+1])) + p)
elif i==L-1:
x_new.append((1-eps)*(r*x[i]*(1-x[i])) + 0.5*eps*(r*x[i-1]*(1-x[i-1]) + r*x[0]*(1-x[0])) + p)
elif i>0 and i<L-1:
x_new.append((1-eps)*(r*x[i]*(1-x[i])) + 0.5*eps*(r*x[i-1]*(1-x[i-1]) + r*x[i+1]*(1-x[i+1])) + p)
return x_new
for p in arange(pLow, pHigh, pInc):
# set initial conditions
state = ic
# throw away the transient iterations
for i in range(nTransients):
state = LM(p, state)
# now stote the next batch of iterates
psweep = [] # store p values
x = [] # store iterates
for i in range(nIterates):
state = LM(p, state)
psweep.append(p)
x.append(state[L/2-1])
plot(psweep, x, 'k,') # Plot the list of (r,x) pairs as pixels
xlabel('Pinning Strength p')
ylabel('X(L/2)')
# Display plot in window
show()
谁能告诉我pylab最后显示的图形有点或线作为标记,如果是线,那么如何用点绘制图表。
这是我使用像素后的输出图像供参考:
【问题讨论】:
-
plot(..., 'k,')的坐标被绘制为点,但在某些部分,点非常密集,因此看起来像线。除此之外,我发现很难理解您的问题(您期望什么结果,或者当前数字有什么问题?)。虽然不是你的问题的一部分,但我写了一个 vectorized version 的LM()函数,它可以加快速度(如果你使用它,请仔细检查!) -
我正在尝试重现一些结果。尽管使用相同的参数值,但无法获得准确的数字。感谢您消除我对绘图命令的疑虑。我不确定我应该扔掉多少个 nTransient,所以我问。我将尝试使用您的 LM() 向量化 sn-p,然后回复您。
-
请告诉我们您要重现的结果!如果我们不知道您希望您的结果是什么样子,很难说您需要纠正什么......
标签: python python-2.7 numpy matplotlib