問11
def question11(f, x_0, x_n, h):
sum_ = 0
x_0 = 1
x_n = 2
n = int((x_n - x_0) / h)
for i in range (1, n + 1):
x_i = x_0 + i * h
sum_ += f(x_i) * h
return sum_
def f(x):
return x / ( x ** 2 + 1)
question11(f, 1, 2, 0.01)
0.4576443659569775
question11(f, 1, 2, 0.001)
0.45809535593707956
question11(f, 1, 2, 0.0001)
0.4581403658370801
question11(f, 1, 2, 0.00001)
0.4581408659360804
question11(f, 1, 2, 0.000001)
0.4581453159370582
question11(f, 1, 2, 0.0000001)
0.4581453609370471