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.

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

Posted at

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