From da4b9239eb0ecdfbdf2411798d8b885cf3d0ed7e Mon Sep 17 00:00:00 2001 From: rtang09 <49603415+rtang09@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:36:01 -0700 Subject: [PATCH] Update simpson_rule.py --- maths/simpson_rule.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/maths/simpson_rule.py b/maths/simpson_rule.py index d66dc39a7171..2eb43e9415c5 100644 --- a/maths/simpson_rule.py +++ b/maths/simpson_rule.py @@ -12,6 +12,14 @@ def method_2(boundary, steps): # "Simpson Rule" # int(f) = delta_x/2 * (b-a)/3*(f1 + 4f2 + 2f_3 + ... + fn) + ''' + >>> method_2([0, 1], 10) + 0.33333333333333326 + >>> method_2([0, 10], 100) + 333.3333333333324 + >>> method_2([-5, 5], 5) + 61.33333333333333 + ''' h = (boundary[1] - boundary[0]) / steps a = boundary[0] b = boundary[1] @@ -48,4 +56,6 @@ def main(): if __name__ == "__main__": + import doctest + doctest.testmod() main()