Question: Question 1 [ 3 5 marks ] The Newton - Raphson method is one of the most commonly used methods for finding roots of general

Question 1[35 marks]
The Newton-Raphson method is one of the most commonly used methods for finding roots of general functions. Given a function f(x), whose roots are to be found, and an initial guess x0, the method can be used to obtain a better approximation of the root as:
x1=x0-f(x0)f'(x0).
The process can be repeated as:
xn+1=xn-f(xn)f'(xn)
until a sufficiently accurate approximation of the root has been obtained.
Write a function, named Newton, implementing the method in Python. Given a function, its derivative, and an initial guess for the root, the Newton function should update the solution using the above formula until a root of sufficient accuracy has been obtained or a predefined number of iterations has been performed. To determine whether solutions are sufficiently accurate, the value of the function for each candidate solution should be compared with a predefined tolerance to ensure it is sufficiently close to zero. In order to avoid zero division errors, the function should test whether the values of the function derivative are less than a predefined numerical tolerance and stop the solution if that is the case. Finally, the function should receive/return the following input/output arguments:
Input arguments
float/None Final solution obtained. In case a zero derivative is encountered, then None should be returned.
Status string, containing information about the solution. Based on how the solution progresses, it should contain the following:
In case the solution has converged, it should contain the message: 'Solution converged after n iterations', where n should be replaced by the number
of iterations performed.
In case the solution has not converged to the required accuracy, it should contain the message: 'Solution not found within the required accuracy,
accuracy of current solution: a, where a is the best accuracy achieved by the method, defined as the absolute value of f at the last iteration
performed.
In case a zero derivative is encountered, it should contain the message: 'Solution interrupted after n iterations, zero derivative encountered' where n
should be replaced by the number of the iteration where the zero derivative was encountered.
In [1]: # YOUR CODE HERE
def Newton , tol=1e-10, maxiterations =28, epsilon=1e-14):
(.....
Newton-Raphson method for finding roots of a function.
Parameters:
 Question 1[35 marks] The Newton-Raphson method is one of the most

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!