Question about Newton Method's modification in Python?
-
How do you Modify the program to allow the user to specify the minimum level of precision in the answer to between 1 and 10 digits to the right of the decimal place. So Far I have: print "This program will compute the square root using Newton's guess and check method" print n=input("Please input the value you wish to find the square root of ") reps=input("Please input the number of times you wish to improve the guess: ") firstguess=n/2.0 nextguess=0 for i in range(reps): nextguess=firstguess firstguess=((firstguess+(n/firstguess)))… print nextguess
-
Answer:
instead of using a for loop for a given number of repetitions, use a while loop and specify a tolerance. something like this: userTol = input("Please enter a tolerance: ") # Number of digits userTol = float('1E-'+str(userTol)) # Convert input to tolerance setting tol = 2*userTol # create a bigger value than userTol while (tol > userTol): # Newton code here tol = abs(firstguess - nextguess)
Ajantha R at Yahoo! Answers Visit the source
Related Q & A:
- What is the difference between a static method and class method in Python?Best solution by pythoncentral.io
- How to access a non static method in an abstract class's static method?Best solution by Stack Overflow
- How to Solve nonlinear system by newton method?Best solution by Mathematics
- What's a good lead for starting off an essay about Isaac Newton?Best solution by en.wikiquote.org
- What's the linear combination method?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.