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.