import numpy as np
import matplotlib.pylab as plt
def phase_func(x, t, a=-1., b=0., c=0., d=-2.):
return np.array([a*x[0]+b*x[1], c*x[0] + d*x[1]])
def phase_focus(x, t, a=1., b=2., c=-2., d=1.):
return np.array([a*x[0]+b*x[1], c*x[0] + d*x[1]])
def phase_saddle(x, t, a=-1., b=-1., c=4., d=1.):
return np.array([a*x[0]+b*x[1], c*x[0] + d*x[1]])
def fitz_nagumo(x, t, a=0.7, b=0.8, c=3, z=-0.00):
return np.array([c*(x[1] + x[0] - x[0]**3/3. + z), -1./c * (x[0] -a + b*x[1])])
def runge_kutta(t0 = 0.0, x0 = np.array([1.0]), t1 = 100., h = 0.01, ng = None):
T = np.arange(t0, t1, h)
N = np.size(T)
X = np.zeros((N, np.size(x0)))
X[0] = x0
for i in xrange(1, N):
x = X[i-1]; t = T[i-1]
w1 = h * ng(x, t)
w2 = h * ng(x + w1 * 0.5, t + 0.5 * h)
w3 = h * ng(x + w2 * 0.5, t + 0.5 * h)
w4 = h * ng(x + w3, t + h)
X[i] = X[i-1] + 1./6. * (w1 + 2*w2 + 2*w3 + w4)
return X,T
def main():
plt.figure()
X, T = runge_kutta(x0 = np.array([-1., -1.]), ng = fitz_nagumo)
plt.plot(T, X[:, 0])
plt.xlabel('x1')
plt.ylabel('x2')
ax = plt.gca()
ax.invert_yaxis()
plt.title('Fitzhuge-Nagumo model(a=0.7, b=0.8, c=3, z=0.0)')
plt.show()
if __name__ == "__main__":
main()