% The program uses the Newton Raphson method to estimate a root of the equation % f(x)=0. The input parameters are x_1 which is an initial estimate of the root % and the tolerance = epsilon with which the root will be estimated. function [x] = NewtonRaphson(x_1,epsilon) % With the next command ask for high accuracy (more decimals) format long % We give an initial value so that the while loop will get started x = x_1 ; % n will count the number of repetitions needed to achieve the desired % accuracy. n=0; % The method while (abs(fcn(x)) > epsilon) x_new = x- fcn(x)/derivfcn(x) % Next estimate of the root. n=n+1 % Number of repetitions. x=x_new; % Set x to be the new estimate in order to calculate again. end