trapezoid rule python
def trap1(f,a,b):
'''heildi f frá a til b með ósamsettri trapisureglu'''
I = (b-a)*(f(a)+f(b))/2
return I
import math
def g(x): return math.sin(x)/x
def h(x): return math.e**x
I1 = trap1(g,1,2)
I2 = trap1(h,0,1)
print(f'I1={I1:.3f}, I2={I2:.3f}')
# prentar "I1=0.648, I2=1.859"