Apr-15-2019, 12:03 PM
The following code is running as it should, however, when it comes to plot the graph,
the command cm.rainbow is printing the same color, and I'd like the legend to have all
values of the iteration according to the range, but I cannot manage to obtain this outcome,
instead it prints exactly whatever I write in the curly brackets.
I am not sure how should I correct my code.
the command cm.rainbow is printing the same color, and I'd like the legend to have all
values of the iteration according to the range, but I cannot manage to obtain this outcome,
instead it prints exactly whatever I write in the curly brackets.
I am not sure how should I correct my code.
def applog(n,x): a0=(1+x)/2 b0=sqrt(x) for i in range(n): a0=(a0+b0)/2 b0=sqrt((a0)*b0) return (x-1)/a0 print("the log approximation is: " , ((applog(4,4)))) print("log value-------------------:" , (np.log(4)) ) error=(abs( applog(4,4)- (np.log(4)) ) ) print("the error is : ", error) x = np.linspace(10, 500, 100) nn=range(1,6) colors = mpl.cm.rainbow(np.linspace(0, 1, len(nn))) for c,n in zip(colors,nn): plt.plot(x, (applog(n,x)),color='c', label='${n}$') plt.plot(x, np.log(x), color='red', label='ln(x)') plt.legend(loc='upper left') plt.show() plt.plot(x,abs(np.log(x)-applog(n,x)) ) plt.show()