PHYCS 3730/6720 Lab Exercise

Reading and references:

Exercise 1

The online notes linked above discuss code for finding the roots of a function using the Newton-Raphson method. Copy the code to a file nr2.py. Look at it to see what it does. Modify the code so it prints out the value of i, p, and pnew at each traversal of the loop, just after evaluating pnew. Test your code to verify that it still works properly.

Copy your modified code to the answer file. (Copy the whole code, please.)

Exercise 2

Starting from the result of Exercise 1, modify the code further, changing the for loop to an equivalent while loop. Use the listed intermediate values of i and p to verify that it does the same thing. Test your code to make sure that it still works properly.

Copy your newly modified code to the same answer file Mylab07.txt.

Exercise 3

Starting from the result of Exercise 1, modify the code so the function call returns both the value of the function and the value of its derivative as a tuple and then proceeds to find the root as before. Test your code to verify that it still works.

Copy your newly modified code to the same answer file Mylab07.txt.