python 2.7 - Write a function to draw a cobweb plot of fixed point iteration -
i have following code draw cobweb function:
def cob_plot(f,x0,n): xvals = [0]*(n+1) xvals[0] = x0 jj in range(1,n+1): xvals[jj] = f(xvals[jj-1]) plt.scatter(xvals[0:n],xvals[1:]) plt.scatter(xvals[1:],xvals[1:]) kk in range(1,n): plt.plot([xvals[kk-1],xvals[kk]],[xvals[kk],xvals[kk]] plt.plot([xvals[kk],xvals[kk]],[xvals[kk],xvals[kk+1]] plt.xlabel("$x_{n-1}$") plt.ylabel("$x_{n}$")
i need modify code function:
cobweb(f, x0, n, xmin, xmax, ymin, ymax)
so cobweb works on function. example:
cobweb(cos, 1, 200, 0, 1.5, 0, 1)
any suggestions or opinions on how modify code? using python 2.7
Comments
Post a Comment