import numpy as np import matplotlib.pyplot as plt # the function of which the fixed point is computed def fix_fun(x): return np.exp(x)/3 # number of steps used in the fixed point iteration num_plot_steps = 21 # initial value of the iteration plt_start_val = 1.5 # create the empty figure and scale the axes correctly # (axes might have to be scaled differently for different functions) plt.figure(1) x_min = -0.2 x_max = 2.5 x_step = 0.01 x_vals = np.arange(x_min,x_max,x_step) plt.axis([x_min,x_max,x_min,max(x_max,fix_fun(x_max))]) plt.axhline(color='k') plt.axvline(color='k') plt.grid(True) # plot the fixed point function... plt.plot(x_vals,fix_fun(x_vals),'b-') # ...and a straight line plt.plot(x_vals,x_vals,'k-') # plotting... x = plt_start_val y = fix_fun(x) plt.plot(x,y,'r',marker='8') for k in np.arange(1,num_plot_steps): plt.plot([x,y],[y,y],'r',marker='8') x = y y = fix_fun(x) plt.plot([x,x],[x,y],'r',marker='8') plt.show()