Mar-27-2019, 01:12 PM
from scipy import integrate a=0 b=1 n=500 h=(b-a)/(n) def f(x): return x**2 def trapezoidal(f,a,b,n): return (h/2)*(f(a)+f(b))+h*( sum(f(a+h*i) for i in range(1, (n-1)))) print(trapezoidal(f,a,b,n)) # Why this? lambda x: f(x) c= integrate.quad(f,0,1) print(c) error=(abs(trapezoidal(f,a,b,n)-c[0]) for n in range (300,900)) for idx, i in enumerate(error): print(idx, i)