Reputation: 300
I'm trying to come up with a python implementation for the Fitzhugh-Nagumo model.
V_t = V_xx + V(V - a)(1 - V) - W + I
W_t = eps(beta*V - W)
Using the really basic code for eps = 0.05, a = 0.2, beta = 5, I = .1
I can numerically solve the system(with out the V_xx
), but I can't seem to figure out how to implement the spacial diffusion.
def func_v(v, w):
return v * (1 - v) * (v - .2) - w + .1
def func_w(v, w):
return .05 * (5 * v - w)
def get_yn(t0, v, w, h, t):
while t0 < t:
w += h * func_w(v, w)
v += h * func_v(v, w)
t0 += h
return v, w
I know the centered difference formula for second order derivatives is
V_xx(x_i, t) = (V(x_i+1, t) - 2*V(x_i, t) + V(x_i-1, t)) / dx^2
but how would I implement the different values for x_i
(let's say from x=0
to 10
) in order to get the wave to propagate along the x-axis?
The results should give a wave that propagates something like this.
Upvotes: 1
Views: 1648
Reputation: 26040
An ODE solver (any computer program really) only can treat problems that have a finite dimensional state. The state in this PDE is a pair of functions v,w
of x
. These can not, in the necessary generality, be represented in a computer. Thus you need to work with finite approximations. A first one that is deemed sufficient in many contexts is the simple function table. Then the x
derivatives are computed using finite difference formulas.
x = np.linspace(0,L,N+1);
dx = x[1]-x[0];
v0,w0 = initial_functions(x);
def func_v(v, w):
d2v = -2*v;
d2v[0] += v[-1]+v[1];
d2v[1:-1] += v[:-2] + v[2:]
d2v[-1] += v[-2]+v[0];
return d2v/dx**2 + v * (1 - v) * (v - .2) - w + .1
etc.
For a proof-of-concept the Euler method may be sufficient, but the values obtained will be questionable. Use a higher order method to get usable results without employing ridiculously small time steps.
Upvotes: 1