問13
def question13(f, x_0, x_n, h):
sum_ = 0
n = int((x_n - x_0) / (h * 2))
for i in range (1, n + 1):
x_i = x_0 + (2 * i - 1) * h
sum_ += (f(x_i + h) + 4 * f(x_i) + f(x_i - h)) * h / 3
return sum_
question13(f, 1, 2, 0.01)
0.45814536585747695
question13(f, 1, 2, 0.001)
0.45814536593706956
question13(f, 1, 2, 0.0001)
0.45814536593707744
question13(f, 1, 2, 0.00001)
0.4581373659130753
question13(f, 1, 2, 0.000001)
0.45814536593708793