Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 一维FitzHugh-Nagumo模型_Python_Numpy_Matplotlib - Fatal编程技术网

Python 一维FitzHugh-Nagumo模型

Python 一维FitzHugh-Nagumo模型,python,numpy,matplotlib,Python,Numpy,Matplotlib,我将用齐次Neumann边界条件解一维FitzHugh-Nagoma。 如何分别绘制U和V。这里a1=2,a0=-0.03,ep=0.01 Du=1,Dv=4,我被图中的图形弄糊涂了 U_t=Du U_xx +U -U^3 - V V_t=Dv V_xx + ep(U-a1V - a0) import numpy as np import matplotlib.pyplot as plt #matplotlib inline Du = 0.001 Dv = 0.005 tau = 1 k =

我将用齐次Neumann边界条件解一维FitzHugh-Nagoma。 如何分别绘制U和V。这里a1=2,a0=-0.03,ep=0.01 Du=1,Dv=4,我被图中的图形弄糊涂了

U_t=Du U_xx +U -U^3 - V
V_t=Dv V_xx + ep(U-a1V - a0)


import numpy as np
import matplotlib.pyplot as plt
#matplotlib inline
Du = 0.001
Dv = 0.005
tau = 1
k = -.00
ep = 0.01
a1 = 2
a0 = -0.03
L = 2
N= 10
x = np.linspace(0, L, N+1)
dx = x[1]-x[0]
T = 45  # total time
dt = .01  # time step
size = N
n = int(T / dt)  # number of iterations
U = np.random.rand(size)
V = np.random.rand(size)
def laplacian(Z):
    Ztop = Z[0:-2]
    Zbottom = Z[2:]
    Zcenter = Z[1:-1]
    return (Ztop + Zbottom -
            2 * Zcenter) / dx**2
def show_patterns(U, ax=None):
    ax.imshow(U, cmap=plt.cm.copper,
          interpolation='bilinear',
          extent=[-1, 1])
    ax.set_axis_off()

fig, axes = plt.subplots(3, 3, figsize=(16, 16))
step_plot = n // 9
# We simulate the PDE with the finite difference
# method.
for i in range(n):
    # We compute the Laplacian of u and v.
    deltaU = laplacian(U)
    deltaV = laplacian(V)
    # We take the values of u and v inside the grid.
    Uc = U[1:-1]
    Vc = V[1:-1]
    # We update the variables.
    U[1:-1], V[1:-1] = \
        Uc + dt * (Du * deltaU + Uc - Uc**3 - Vc),\
        Vc + dt * (Dv * deltaV + ep*(Uc - a1*Vc - a0)) / tau
    # Neumann conditions: derivatives at the edges
        # are null.
    for Z in (U, V):
        Z[0] = Z[1]
        Z[-1] = Z[-2]
       # Z[:, 0] = Z[:, 1]
       # Z[:, -1] = Z[:, -2]

    # We plot the state of the system at
    # 9 different times.
fig, ax = plt.subplots(1, 1, figsize=(8, 8))
show_patterns(U,ax=None)
我得到一个错误'NoneType'对象没有属性'imshow' 无法解决这一问题

show_patterns(U,ax=None)
None
传递给
ax
参数

我不知道ax应该是什么,但需要正确初始化。

我已将show_模式(U,ax=None)更改为show_模式(U,ax=ax),但不起作用