Homework 2

Due: Feb 3 by 11:55 pm (London ON time)
Submit your Jupyter Notebook to OWL

Netwon’s method for square root

Write a short program to estimate the square root of any number using Newton’s method. Write your program so that the number whose square root is to be taken, and the number of iterations to be used, are both variables that can be set at the top of the program. You can choose the initial guess on your own, use whatever you like. I suggest the number 10.0 as in the Wikipedia example.

Find the square root of 612 using 5 iterations.

This is the relevant section of the Wikipedia entry and the only bit you need in order to complete this assignment. The relevant equation is highlighted in a red box.

The idea is you start with an initial guess (in this case, 10). The initial guess is then passed through an equation (shown in the red box) to refine it (in the example, it gets refined to 35.6). That refined guess then becomes the next guess which is passed through the same equation again, and further refined.

Hint: the first 3 iterations (after the initial guess of 10) should produce this:


Find the square root of 612 using 5 iterations, report the value to 10 decimal places.

Report the error compared with the math.sqrt() function in Python to 15 decimal places.

Your program should output the following:

Enter a number x and I will compute sqrt(x): 612
How many iterations: 5
after 5 iterations, sqrt(612.000) = 24.7386337538
the error is 0.000000000060123