TypeError: unsupported operand type(s) for -: 'int' and 'function'

def simpson(a, b, n2, f):
    h2 = (b - a) / (2 * float(n2))

    tmp_sum = f(b)+f(a)

    for step in range(1, 2 * n2):
        if step % 2 != 0:
            tmp_sum += 4 * f(a + step * h2)
        else:
            tmp_sum += 2 * f(a + step * h2)

    return tmp_sum * h2 / 3


    n2 = 2
    a5 = simpson(f, 1, 1.6, n2)
    n2 *= 2
    a6 = simpson(f, 1, 1.6, n2)

    while abs(a5 - a6) > 0.01:
        n2 *= 2
        a5 = simpson(f, 1, 1.6, n2)
        n2 *= 2
        a6 = simpson(f, 1, 1.6, n2)
    print("\nОтвет метод Симпсона:", a5, "\nКоличество разбиений:", n2)
    print("Конец метода Симпсона")

выдает вот такую ошибку, хотя таким же принципом сделал метод трапеции и все ок

Traceback (most recent call last):
  File "/home/kirill/zsdanie1/main.py", line 86, in <module>
    a5 = simpson(f, 1, 1.6, n2)
  File "/home/kirill/zsdanie1/main.py", line 72, in simpson
    h2 = (b - a) / (2 * float(n2))
TypeError: unsupported operand type(s) for -: 'int' and 'function'

Ответы (0 шт):