From 8adb0fcbe1de0d401dd400ff8257481c75c00739 Mon Sep 17 00:00:00 2001 From: teridax Date: Mon, 22 May 2023 18:16:45 +0200 Subject: [PATCH] added integral approximation --- integral_approximation/__init__.py | 31 ++++++++++++++++++++++++++++++ main.py | 2 ++ 2 files changed, 33 insertions(+) create mode 100644 integral_approximation/__init__.py diff --git a/integral_approximation/__init__.py b/integral_approximation/__init__.py new file mode 100644 index 0000000..551cf3e --- /dev/null +++ b/integral_approximation/__init__.py @@ -0,0 +1,31 @@ + +def integral_approximation(function, divisions, interval): + delta = (interval[1] - interval[0]) / divisions + + maximum = 0.0 + minimum = 0.0 + + x0 = interval[0] + + for i in range(0, divisions): + x1 = x0 + delta + + y0 = function(x0) * delta + y1 = function(x1) * delta + + maximum += max(y0, y1) + minimum += min(y0, y1) + + x0 = x1 + + average = (maximum + minimum) / 2 + + print("maximum: %s minimum: %s average: %s" % (maximum, minimum, average)) + + +def f(x): + return (x - 4) * (x + 8) * (x - 50) * (x - 37) * 0.0001 + + +def test(): + integral_approximation(f, 1200, [3, 4]) diff --git a/main.py b/main.py index ac7bbba..c6a003b 100644 --- a/main.py +++ b/main.py @@ -20,6 +20,7 @@ import matrix import newton_polynom import zero_point_approximation import taylor_sine_approx +import integral_approximation if __name__ == '__main__': linear_approximation.test() @@ -28,3 +29,4 @@ if __name__ == '__main__': zero_point_approximation.test() matrix.test() taylor_sine_approx.test() + integral_approximation.test()