Under no circumstances will late assignments be accepted.
The code you submit must conform with the programming guidelines.
double root(double a, int n, double x0, double epsilon);
that finds the n-th root of a positive floating point number a via Newton-Raphson approximation.
Your function should detect the following error cases:Your function should have no side-effects (e.g., no printing error messages).
This method actually yields the same algorithm for finding square roots as does the classical Greek method. Finding sqrt(a) is the sames as finding the zero of f(x) = x^2 - a. Thus,
Given an initial value for x (x0), the above equation is evaluated iteratively until the change in the value of x is less than a numerical tolerance, epsilon:
This method generalizes to find n-th roots. In this assignment we find the n-th root via Newton-Raphson, by finding the zero of the function f(x) = x^n - a.
Hint: You are welcome to use the math function pow().
Notes: Only submit the function double root(double a, int n, double x0, double epsilon) in root.cpp. Do not submit a program main(). You cannot alter the function name nor arguments as specified in the function prototype given for root. Your function should not have any side effects.
Testing: You are responsible for thoroughly testing your program to make sure that it works. In grading your program, we will test your program on some standard tests. Be sure that your function can correctly find the root when n>0, and when n<0.