【问题标题】:1D FitzHugh Nagumo modelFitzHugh Nagumo 1D模型
【发布时间】:2020-05-10 22:58:49
【问题描述】:

我将使用齐次 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) 更改为 show_patterns(U,ax=ax) 但不起作用

标签: python numpy matplotlib


【解决方案1】:

这一行

show_patterns(U,ax=None)

None 传递给ax 参数。

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

【讨论】:

    猜你喜欢
    • 2016-11-02
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    • 2021-05-17
    • 2018-10-29
    • 2020-03-03
    相关资源
    最近更新 更多