Simpson's Rule

Simpson's Rule is a more accurate method of numerical integration than the method illustrated above. Using Simpson's Rule, the integral of a function f between a and b is approximated as

1.29

where h = (b − a)/n , for some even integer n , and yₖ = f(a + kh) . (Increasing n increases the accuracy of the approximation.) Define a procedure simpson that takes as arguments f , a , b , and n and returns the value of the integral, computed using Simpson's Rule. Use your procedure to integrate cube between 0 and 1 (with n = 100 and n = 1000), and compare the results to those of the integral procedure shown above.


    # Mihhail
    1 year ago

    Точно ли правильный тест номер 3?, ведь уже на n=2 получается точное решение в 1/4 без округлений, если на бумажке посчитать?

    # voxman90 Replied to Mihhail #
    7 months ago
    Точно ли правильный тест номер 3?, ведь уже на n=2 получается точное решение в 1/4 без округлений, если на бумажке посчитать?

    Если кто столкнётся с той же проблемой, нужно в промежуточных вычислениях использовать числа с плавающей запятой. Без этого процедура действительно возвращает 1/4 даже для n = 2.

Authentication required

You must log in to post a comment.

Login