## Answers

function [root,fx,ea,iter] = modnewtraph(func,x0,h,es,maxit ,method,p)

switch nargin %this is used to set the default values so it required at leat three input , otherwise it will show error

case 3

es = 0.0001 ;

maxit = 50;

method = "C";

p = 0 ; % additional parameter for function

case 4

maxit = 50;

method = "C";

p = 0 ;

case 5

method = "C";

p = 0 ;

case 6

p = 0;

end

are = 10 ; %%initialise approximate relative error as 10

X0 = x0;

itr = 0; %% initialise iteration variable to keep track of no. of iteration

while(are> es) %%% check if the current ARE is greater then the desired error

itr = itr + 1 ; % increment the itration value to keep track of iteration

if(method =="F")

F_dotX = (func(X0 + h,p) - func(X0,p))/h; %%for Forward finite difference

else

F_dotX = (func(X0 + h,p) - func(X0-h,p))/(2*h); %calculate the derivative of function according to the method,for %centered finite difference

end;

X1 = X0 - func(X0,p)/F_dotX; %apply Newton_Raphson rule , RECURRENCE formula

are = abs(X1-X0)*100/abs(X0) ;%Calculate approximate relative error

X0 = X1;

if(maxit ==itr) %%while the iteration is equal to maximum iterarion break the loop

break;

end;

end

fx = func(X1,p);

root =X1;

ea = are;

iter=itr;

end

%%%PLEASE UPVOTE !!!!! THANKS

.