Skip to content

Instantly share code, notes, and snippets.

@emwdx
Created August 31, 2012 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emwdx/3551674 to your computer and use it in GitHub Desktop.
Save emwdx/3551674 to your computer and use it in GitHub Desktop.
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