clear close f=@(x)x.^3-2*x.^2+1; df=@(x)3*x.^2-4*x; a=-1;b=0;N=5; x0=-1; E=0.001; x=linspace(a,b); plot(x,f(x)) hold on plot([-1 0],[0,0],'k-') set(gca,'XTick',[],'YTick',[]) title('Newton-Raphson','Fontsize',16,'Fontweight','b') pause plot([x0 x0],[0 f(x0)],'r-') text(x0+0.01,0.1,['x_',num2str(0)],'Fontsize',16,'Fontweight','b') pause for n=1:2 x1=x0-f(x0)/df(x0); plot([x0 x1],[f(x0) 0],'r-') text(x1+0.01,0.1,['x_',num2str(n)],'Fontsize',16,'Fontweight','b') pause plot([x1 x1],[0 f(x1)],'r-') pause x0=x1; end