def f(x): return _poly.eval(a, x) # evaluate polynomial a as a function xl, xu = -5, 5
#estimate plotting x range xlo = x0 - (xn - x0) / 50. xhi = xn + (xn - x0) / 50. #plot function f(x) m = 1000 #number of points for smooth plotting effect xpts = np.linspace(xlo, xhi, m) plt.plot(xpts, f(xpts), 'b', label='true function') #draw vertical segments & interpolation points for integral estimate #TO DO... #fill area for integral estimate xpts = np.linspace(x0, xn, m) parabolic_coefs = _polyreg.curvefit(axpts, aypts, order=2) ypts = _poly.eval(parabolic_coefs, xpts) plt.fill_between(xpts, ypts, facecolor='g', alpha=.2, edgecolor='g', label='integral estimate') #fill area for error #TO DO... #show plot w/ title, legend, etc. plt.title("Single application of Simpson's 1/3 integration rule") plt.legend(loc="upper left", shadow=True) plt.xlabel('x-axis') plt.ylabel('y-axis')
def f(x): return _poly.eval(a, x)
def f(x): return _poly.eval(a, x) # Graphical Solution xl, xu = -5, 5