-4

Whenever I enter in this code, I get an OverflowError: math range error at the 4th line. How do I fix it?

x=0
while True:
    x=int(x)+1
    first_root=first_root-((a*(math.pow(first_root, 3)))+(b*(math.pow(first_root, 2))+(c*first_root)+d)/(3*(a*   (math.pow(first_root, 2))))+(2*(b*first_root))+c)
    if x==30:
        break
vidit
  • 6,007
  • 3
  • 28
  • 46
user2442129
  • 1
  • 2
  • 3

1 Answers1

0

The simple answer is that the equation you are using does not have a root. you can see this by using a print first_root statement inside your while loop and seeing that it diverges to +-inf.

However, assuming your textbook isn't screwing with you, and the equation does have a root I can almost guarantee that you have a parenthesis in the wrong spot. Below is your exact code with all of the unneeded parenthesis removed and first_root replaced with r to make it easier to read.

r = r - a*pow(r, 3) + b*(pow(r, 2) + c*r + d) / 3*a*pow(r, 2) + 2*b*r + c

What you need to do is compare this with the equation in your book and see where/if you messed it up.

bcorso
  • 40,568
  • 8
  • 56
  • 73
  • BTW, my guess is that the first "b" should only be multiplied by r^2 and not the other terms. – bcorso Jun 02 '13 at 19:10