LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

プログラミング問題集解答例(問11)

Last updated at Posted at 2019-12-04

問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
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up