def test_sloping_line():
''' a simple linear function '''
def line(x):
return 2 + 3*x
# I got 159.99999999999 rather than 160
# hence the need for isclose()
assert isclose(trapz(line, 2, 10), 160)
m, B = 3, 2
a, b = 0, 5
assert isclose(trapz(line, a, b), 1/2*m*(b**2 - a**2) + B*(b-a))
a, b = 5, 10
assert isclose(trapz(line, a, b), 1/2*m*(b**2 - a**2) + B*(b-a))
a, b = -10, 5
assert isclose(trapz(line, a, b), 1/2*m*(b**2 - a**2) + B*(b-a))
评论列表
文章目录