Aug-15-2021, 05:38 PM
The program is for finding approximate values of an integral using the trapezoid method, but it is in an infinite loop. I couldn't find the error.
intervalo = input("Entre com o número de intervalos : ") a = 1 b = 3 n = float (intervalo) c = float (a) soma = 0 # FUNÇÃO : 1/x^2 def f(x): return 1/(x)**2 h = math.fabs (b-a)/n c += h def tpz(f,a,b,c,n): while f(c) < b): soma = (f(c) + f(c + h)) c += h soma *= 2 soma = ((f(a) + f(b)) + soma) * h/2 d = tpz(f,a,b,c,n) print("O resultado da integral é aproximadamente :",d)