answer=inputdlg({'x0=','f(x)=','f''(x)='},'',1,{'6','cos(x)','-sin(x)'});

x0= str2num(answer{1});
fstr= answer{2};
f= @(x)eval(fstr);
dfstr= answer{3};
df= @(x)eval(dfstr);

x= x0;
xmin= x;
xmax= x;
figure
while abs(f(x))>1e-3
    xold= x;
    
    x= x-f(x)/df(x);
    disp(['x=' num2str(x)]);
    
    plot([xold x],[f(xold) 0],'r-*');
    hold on
    plot([x x],[0 f(x)],'m:');
    if x<xmin
        xmin= x;
    end;
    if x>xmax
        xmax=x;
    end;
end;
fvstr= vectorize(fstr);
fv= @(x)eval(fvstr);

xa=xmin:(xmax-xmin)/100:xmax;
plot(xa,fv(xa));
grid on
msgbox(num2str(x));

