Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
TuringTest
Group Title
Python: NewstonRaphson
I am getting too many iterations and my answer is off in the millions decimal place. Any ideas?
 one year ago
 one year ago
TuringTest Group Title
Python: NewstonRaphson I am getting too many iterations and my answer is off in the millions decimal place. Any ideas?
 one year ago
 one year ago

This Question is Closed

TuringTest Group TitleBest ResponseYou've already chosen the best response.0
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 #NewtonRaphson 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...
 one year ago

TuringTest Group TitleBest ResponseYou've already chosen the best response.0
my answer is within epsilon of the given answer, so I'm really just worried about the iterations
 one year ago

KonradZuse Group TitleBest ResponseYou've already chosen the best response.0
A million decimal places.....? or the millionths place? :P
 one year ago

TuringTest Group TitleBest ResponseYou've already chosen the best response.0
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.
 one year ago

KonradZuse Group TitleBest ResponseYou've already chosen the best response.0
is # a comment?
 one year ago

TuringTest Group TitleBest ResponseYou've already chosen the best response.0
yes and never mind, problem solved!
 one year ago

ishesh Group TitleBest ResponseYou've already chosen the best response.0
if the problem is solved could u pls giv me the soln??
 one year ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.