Placeholder

Newton’s Method for Approximating Square Roots

$25.00

Description

These projects must be done in the latest version of IDLE:
Package Newton’s method for approximating square roots (Case Study 3.6) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key.
Convert Newton’s method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of the square root should be passed as a second argument to the function.)
Elena complains that the recursive newton function in Project 2 includes an extra argument for the estimate. The function’s users should not have to provide this value, which is always the same, when they call this function. Modify the definition of the function so that it uses a keyword parameter with the appropriate default value for this argument, and call the function without a second argument to demonstrate that it solves this problem.
Restructure Newton’s method (Case Study 3.6) by decomposing it into three cooperating functions. The newton function can use either the recursive strategy of Project 1 or the iterative strategy of Case Study 3.6. The task of testing for the limit is assigned to a function named limitReached, whereas the task of computing a new approximation is assigned to a function named improveEstimate. Each function expects the relevant arguments and returns an appropriate value.
A list is sorted in ascending order if it is empty or each item except the last one is less than or equal to its successor. Define a predicate isSorted that expects a list as an argument and returns True if the list is sorted, or returns False otherwise. (Hint: For a list of length 2 or greater, loop through the list and compare pairs of items, from left to right, and return False if the first item in a pair is greater.)
SCREENSHOTS
SOLUTION
PAYMENT
The solution includes five python programs.
Attachments [Move over files to preview content of those files]
Python_Newton_Methods.zip (264.39 KB)
Python programs
Program1.py
Program2.py
Program3.py
Program4.py
Program5.py
Python-Newton-Method-Program-1-Screenshot.png
Python-Newton-Method-Program-2-Screenshot.png
Python-Newton-Method-Program-3-Screenshot.png
Python-Newton-Method-Program-4-Screenshot.png
Python-Newton-Method-Program-5-Screenshot.png
Preview Program1.py
#xxxxxxx xxxxxx’x xxxxxx xxx xxxxxxxxxxxxx xxxxxx xxxxx (xxxx xxxxx 3.6) xx x xxxxxxxx xxxxx xxxxxx.
# xxxx xxxxxxxx xxxxxxx xxx xxxxx xxxxxx xx xx xxxxxxxx xxx xxxxxxx xxx xxxxxxxx xx xxx xxxxxx xxxx.
# xxx xxxxxx xxxxxx xxxx xxxxxxx x xxxx xxxxxxxx xxxx xxxxxx xxx xxxx xx xxxxxxx xxxxxx xxxxx xx xxxxxx
# xxxxx xxx xxxxxxx xxx xxxxx/xxxxxx xxx.
import math
def newtonSquare(x): # Initialize the tolerance and estimate tolerance = 0.000001 estimate = 1.0 # Per orm the successive approximations
xxxxx (“xxxxx xxxxx xx xxxx xxx xxxxxxxxxxx…”)
xxxxx xxxx:
xxxxxxxx = (xxxxxxxx + x / xxxxxxxx) / 2
xxxxxxxxxx = xxx(x – xxxxxxxx ** 2)
xx xxxxxxxxxx <= xxxxxxxxx: xxxxx Preview Program2.py #xxxxxxx xxxxxx’x xxxxxx xxx xxxxxxxxxxxxx xxxxxx xxxxx xx xxxxxxx 1 xx x xxxxxxxxx xxxxxxxx xxxxx xxxxxx. # (xxxx: xxx xxxxxxxx xx xxx xxxxxx xxxx xxxxxx xx xxxxxx xx x xxxxxx xxxxxxxx xx xxx xxxxxxxx.) xxxxxx xxxx def newton(x, estimate): if abs(x-estimate ** 2) <= 0.000001: return estimate else: estimate = newton(x, (estimate + x / estimate) / 2) return estimate def main(): # xxxxxxx xxx xxxxx xxxxxx xxx xxx xxxx xxxxx xxxx: x = xxxxx('xxxxx x xxxxxxxx xxxxxx xx xxxxx "xxxxx" xx xxxx: ') xx x == '': xxxxx xxxx: Preview Program3.py # xxxxx xxxxxxxxx xxxx xxx xxxxxxxxx xxxxxx xxxxxxxx xx xxxxxxx 2 xxxxxxxx xx xxxxx xxxxxxxx xxx xxx xxxxxxxx. # xxx xxxxxxxx’x xxxxx xxxxxx xxx xxxx xx xxxxxxx xxxx xxxxx, xxxxx xx xxxxxx xxx xxxx, xxxx xxxx xxxx xxxx xxxxxxxx. # xxxxxx xxx xxxxxxxxxx xx xxx xxxxxxxx xx xxxx xx xxxx x xxxxxxx xxxxxxxxx xxxx xxx xxxxxxxxxxx xxxxxxx xxxxx # xxx xxxx xxxxxxxx, xxx xxxx xxx xxxxxxxx xxxxxxx x xxxxxx xxxxxxxx xx xxxxxxxxxxx xxxx xx xxxxxx xxxx xxxxxxx. import math def newton(x, estimate = 1.0): if abs(x-estimate ** 2) <= 0.000001: return estimate else: estimate = newton(x, (estimate + x / estimate) / 2) xxxxxx xxxxxxxx xxx xxxx(): # xxxxxxx xxx xxxxx xxxxxx xxx xxx xxxx xxxxx xxxx: x = xxxxx('xxxxx x xxxxxxxx xxxxxx xx xxxxx "xxxxx" xx xxxx: ') xx x == '': Preview Program4.py # xxxxxxxxxxx xxxxxx’x xxxxxx (xxxx xxxxx 3.6) xx xxxxxxxxxxx xx xxxx xxxxx xxxxxxxxxxx xxxxxxxxx. # xxx xxxxxx xxxxxxxx xxx xxx xxxxxx xxx xxxxxxxxx xxxxxxxx xx xxxxxxx 1 xx xxx xxxxxxxxx xxxxxxxx xx xxxx xxxxx 3.6. # xxx xxxx xx xxxxxxx xxx xxx xxxxx xx xxxxxxxx xx x xxxxxxxx xxxxx xxxxxxxxxxxx, # xxxxxxx xxx xxxx xx xxxxxxxxx x xxx xxxxxxxxxxxxx xx xxxxxxxx xx x xxxxxxxx xxxxx xxxxxxxxxxxxxxx. # xxxx xxxxxxxx xxxxxxx xxx xxxxxxxx xxxxxxxxx xxx xxxxxxx xx xxxxxxxxxxx xxxxx. import math def limitReached(temp): if temp <= 0.000001: return True return False xxx xxxxxxxxxxxxxxx(x, xxxxxxxx): xxxxxx (xxxxxxxx + x / xxxxxxxx) / 2 xxx xxxxxx(x, xxxxxxxx = 1.0): xx xxxxxxxxxxxx(xxx(x-xxxxxxxx ** 2)) == xxxx: Preview Program5.py # x xxxx xx xxxxxx xx xxxxxxxxx xxxxx xx xx xx xxxxx xx xxxx xxxx xxxxxx xxx xxxx xxx xx xxxx xxxx xx xxxxx xx xxx xxxxxxxxx. # xxxxxx x xxxxxxxxx xxxxxxxx xxxx xxxxxxx x xxxx xx xx xxxxxxxx xxx xxxxxxx xxxx xx xxx xxxx xx xxxxxx, xx xxxxxxx xxxxx xxxxxxxxx. # (xxxx: xxx x xxxx xx xxxxxx 2 xx xxxxxxx, xxxx xxxxxxx xxx xxxx xxx xxxxxxx xxxxx xx xxxxx, xxxx xxxx xx xxxxx, # xxx xxxxxx xxxxx xx xxx xxxxx xxxx xx x xxxx xx xxxxxxx.) def isSorted(myList): for i in range(len(myList)-1): if myList[i] >= myList[i+1]: return False return True
def main():
xxxxxx = xxxxx(“xxxxx x xxxx xx xxxxxxxx: >> “)
xxxxxx = xxxx(xxx(xxx, xxxxxx.xxxxx()))
xx (xxxxxxxx(xxxxxx)) :
xxxxx (“xxx xxxx xx xxxxxx xx xxxxxxxxx xxxxx”)
xxxx:
xxxxx (“xxx xxxx xx xxx xxxxxx xx xxxxxxxxx xxxxx”)
Price: $25
Buy Now
Checkout
Added to cart
Buy More Save More
Buy at least TWO items & save up to 30% OFF your ENTIRE order!
Rack up instant rebates in your shopping cart. Simply add items to your cart, and see the savings add up.
Discounts will automatically be applied on eligible orders.
Newton’s Method Project 1 – $5.00
Newton’s Method Project 2 – $5.00
Newton’s Method Project 3 – $5.00
Newton’s Method Project 4 – $5.00
Newton’s Method Project 5 – $5.00
Add to Cart
Checkout
Added to cart
You May Also Like:
Python Assignments Caesar Cipher
Python Assignments Triangle and Guessing Number
Python Assignments Credit Plan and Series Numbers
Python Assignments Stats Read File and Sentence Generator

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.