Skip to content

Instantly share code, notes, and snippets.

Created August 31, 2012 11:25
What would you like to do?
Trapezoidal Rule for definite integrals
a = 0
b = 1
N = 500
area = 0
delta_x = (b - a)*1./N
def f(t):
return t**2
for i in range(N):
x = i*delta_x + a
area=area + 0.5*(f(x)+f(x+delta_x))*delta_x
print area
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment