trapezoid rule python

Solutions on MaxInterview for trapezoid rule python by the best coders in the world

showing results for - "trapezoid rule python"
Charlene
02 Jan 2019
1def trap1(f,a,b):
2    '''heildi f frá a til b með ósamsettri trapisureglu'''
3    I = (b-a)*(f(a)+f(b))/2
4    return I
5
6import math
7def g(x): return math.sin(x)/x
8def h(x): return math.e**x
9
10I1 = trap1(g,1,2)
11I2 = trap1(h,0,1)
12print(f'I1={I1:.3f}, I2={I2:.3f}')
13    # prentar "I1=0.648, I2=1.859"
14