Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Infinite loop
#1
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)
Reply


Messages In This Thread
Infinite loop - by Danado - Aug-15-2021, 05:38 PM
RE: Infinite loop - by deanhystad - Aug-15-2021, 08:13 PM
RE: Infinite loop - by Danado - Aug-15-2021, 08:37 PM
RE: Infinite loop - by Danado - Aug-15-2021, 09:48 PM
RE: Infinite loop - by deanhystad - Aug-16-2021, 05:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with while loop creating an infinite loop. FWendeburg 3 3,156 Jan-30-2019, 08:28 PM
Last Post: FWendeburg
  Infinite loop/ only half working anclark686 5 4,864 Sep-09-2018, 07:31 AM
Last Post: buran
  Why is this giving me an infinite loop? wlsa 4 4,014 Jul-25-2018, 10:11 PM
Last Post: cyberpatje
  Another infinite loop wlsa 7 4,809 Jul-20-2018, 12:04 AM
Last Post: wlsa
  How to stop an infinite loop in spyder if it's currently running? wlsa 3 24,849 Jun-30-2018, 03:27 AM
Last Post: ichabod801
  Infinite loop Truman 9 9,287 Jan-19-2018, 11:25 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020