Exercise 7

Newton's Method for Square Root

Write a program to estimate the square root of 612 using Newton's method. Write it so that the number whose square root is to be taken, and the number of iterations are both parameters (variables) that can be set by the user or the programmer. 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. Try it again using 10 iterations.


Examine the relationship between the square root of 612 as found by Newton's method as a function of the number of iterations. Examine iterations from 1 through to 10. If you want to get a head start on how to visualize data, you can try to plot this relationship.

Repeat this using different starting guesses, e.g. 5, 10, 20, 40, 80

Plotting hints: in MATLAB use the plot() command. In R use the plot() command.

In Python either issue the command:

from matplotlib import *

or instead of starting Python, start iPython:

ipython --pylab

and then the plot command is already at your disposal.

In C, I would suggest exporting the data to a file and then importing it into MATLAB, Python or R to do the plotting.

We will look at graphical displays of data in more detail soon…


Paul Gribble | fall 2014
This work is licensed under a Creative Commons Attribution 4.0 International License
Creative Commons License