% _________________________________________________________________________ % To get accurate root of given equation by Newton-Raphson method % By Mahesha MG, MIT % Date: 14/03/2013 % _________________________________INPUT___________________________________ clc; clear; y = inline('x^2+x-2'); %Equation dy = inline('2*x+1'); %Derivative of the equation x0=input('Enter approximate root: '); e=input('Enter the accuracy: '); %Example: 1e-5 % _________________________Newton Raphson method___________________________ while abs(feval(y,x0))>e h=-feval(y,x0)/feval(dy,x0); x0=x0+h; end % _________________________________________________________________________ root=x0