Skip to content

Instantly share code, notes, and snippets.

@KelviNosse
Created June 22, 2016 23:42
Show Gist options
  • Save KelviNosse/48043e4224ce5dc41cbe9282a8534b8a to your computer and use it in GitHub Desktop.
Save KelviNosse/48043e4224ce5dc41cbe9282a8534b8a to your computer and use it in GitHub Desktop.
Integrating sin(x) using Simpson Rule
#Integracion Simpson en funcion seno
#
from math import *
def f(x):
return sin(x)
def simpson_rule(a,b):
c=(a+b)/2.0
h=abs(b-a)/2.0
return h*(f(a)+4.0*f(c)+f(b))/3.0
val_a = input("Ingrese el valor a: ")
val_b = input("Ingrese el valor b: ")
res = simpson_rule(val_a, val_b)
print "Valor aproximado de la integracion: "+str(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment