stabilityAllTaylors.py

#
# Stability regions for Taylor's methods
# Vincent Legat - 2018
# Ecole Polytechnique de Louvain
#

import matplotlib.pyplot as plt
from numpy import *
from math import factorial


x,y = meshgrid(linspace(-4,4,1000),linspace(-3,3,1000))
z = x + 1j*y

plt.figure("Stability of Taylor's Methods ")

for n in [4,3,2,1]:
  f = ones(shape(z)) 
  for m in range(n,0,-1):
    f = f + z**m/factorial(m)
  f = abs(f)
  plt.contourf(x,y,f,[0,1,100],colors=('lightgreen','none'))
  plt.contour(x,y,f,[1],colors='black',linewidths=0.5)

ax = plt.gca()
ax.axhline(y=0,color='gray',linewidth=0.5)
ax.axvline(x=0,color='gray',linewidth=0.5)
#ax.yaxis.grid(color='gray',linestyle='dashed')
#ax.xaxis.grid(color='gray',linestyle='dashed')
plt.xticks(arange(-3,4,1))
plt.yticks(arange(-3,4,1))
plt.axis('equal')
plt.show()