added integral approximation

This commit is contained in:
Sven Vogel 2023-05-22 18:16:45 +02:00
parent 5d1c02080f
commit 8adb0fcbe1
2 changed files with 33 additions and 0 deletions

View File

@ -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])

View File

@ -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()