Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

Python: Newston-Raphson I am getting too many iterations and my answer is off in the millions decimal place. Any ideas?

Computer Science
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SIGN UP FOR FREE
poly=(-13.39,0.0,17.5,3.0,1.0) x=0.1 epsilon=0.001 def evaluate_poly(poly, x): #evaluates a polynomial input as a tuple for a specific x value value=0 power=0 for i in poly: value+=i*x**power power+=1 return value def compute_derivative(poly): #returns a tuple representing the derivative #of the input polynomial as a tuple power=0 deriv=() for i in poly: deriv+=(i*power,) power+=1 return deriv def compute_root(poly, x, epsilon): #find the root of the polynomial poly using #Newton-Raphson method iterations=0 deriv=compute_derivative(poly) derivValue=evaluate_poly(deriv, x) #evaluates the current x value of the derivative of the polynomial value=evaluate_poly(poly, x) while abs(value) > epsilon: value=evaluate_poly(poly, x) derivValue=evaluate_poly(deriv, x) x-=value/derivValue iterations+=1 return x, iterations #outputs a the root and number of iterations as a tuple I get an output of (0.80679329312..., 139) the answer is supposed to be (0.806790679..., 8) My answer for the root is darn close, but why so am I getting so many iterations? I tried debugging it but all the numbers seem normal on every iteration, I'm just not getting there fast enough somehow...
my answer is within epsilon of the given answer, so I'm really just worried about the iterations
A million decimal places.....? or the millionths place? :P

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

The millionth place, actually I had the wrong value for epsilon, it should have been 0.0001 with that correction I get (0.8067887806273476, 141) and the given answer is (0.80679075379635201, 8) Since my answer and the given answer differ by a number less than epsilon=0.0001 the answer is not what I'm worried about, it's the fact that my algorithm uses 141 iterations when it's only supposed to use 8 ! I'm going to do this painfully on paper and see if I can debug this to find which variable(s) is/are misbehaving.
is # a comment?
yes and never mind, problem solved!
if the problem is solved could u pls giv me the soln??

Not the answer you are looking for?

Search for more explanations.

Ask your own question