from math import * import matplotlib.pyplot as plt def f(x): return 18*x*sin(0.79*x) a = 0; b = 4.5; N = 9 n = 10 # Use n*N+1 points to plot the function smoothly step = (b-a)/N s = (b-a)/(n*N) x = [0]*(N+1) x[0]=a for i in range(1,N+1): x[i]=x[i-1]+step y = [0]*(N+1) for i in range(N+1): y[i] = f(x[i]) X = [0]*(n*N) X[0]=a for i in range(1,n*N): X[i]=X[i-1]+s Y = [0]*(n*N) for i in range(n*N): Y[i] = f(X[i]) plt.plot(X,Y,'r') x_left = x[:-1] # Left endpoints y_left = y[:-1] x_plot = [0]*(N) for i in range (1,N): x_plot[i] = x[i]+.25 plt.bar(x_plot,y_left, 0.5,color="red") plt.grid() plt.show()