Home /
Expert Answers /
Computer Science /
algorithm-for-newton-raphson-method-set-max-number-of-iterations-around-20-compute-f-0-f-l-pa825
(Solved): Algorithm for Newton-Raphson Method: Set max number of iterations (around 20). Compute \( f_{0}=f\l ...
Algorithm for Newton-Raphson Method: Set max number of iterations (around 20). Compute \( f_{0}=f\left(x_{0}\right) \) Compute \( f^{\prime}\left(x_{0}\right) \), check that it is non-zero. (if \( f^{\prime}\left(x_{k}\right) \) at any stage is zero, print an error message and return None - This will terminate the execution of the function.) While \( \left|f_{0}\right|> \) tolerance and max iterations not exceeded, Calculate \( x_{1}=x_{0}-\frac{f\left(x_{0}\right)}{f^{\prime}\left(x_{0}\right)} \) Set \( x_{0}=x_{1}, \quad f_{0}=f\left(x_{0}\right) \) increase iteration count. when loop terminates, report \( x_{1} \) as the approximation and the number of iterations. Print the number of function evaluations: (count neach time \( f \) or \( f^{\prime} \) is evaluated) The newton-raphson function should accept \( f, f^{\prime}, x_{0}, \epsilon \) as input parameters and should output the approximation and the number of iterations. (1) Test your program by plotting and finding the roots of \( f(x)=\ln (2+x)-\sqrt{x} \) using \( \left[x_{0}, x_{1}\right]=[0,10] \). Plot the function over \( [0,10] \). Use a tolerance of \( 10^{-8} \). Print \( x,|f(x)| \) and the number of iterations required for convergence. Compare with the results from bisection. (Note: \( f(x)=\ln (x+2)-\sqrt{x} \); \( d f / d x(x)=1 /(x+2)-1 /(2 \sqrt{x})) \)