% demonstracni priklad pro predvedeni newtonovy metody 
% sepsal Jan Nejedly 2003
% 
% ukazka bude provedena na f(x)=(x/2)^2-sin(x)

a=1.4;
b=2.3;
kroku=20;
presnost=.001;
start=1.5;


x0=a:0.01:b;
yo=(x0/2).^2-sin(x0);
plot(x0,yo);
grid on;
hold on;

x=start;
for i=1:kroku
  fx=(x/2)^2-sin(x);
  dfx=x/2-cos(x);
  
  new=x-fx/dfx;
  plot(x,0,'rx');
  plot([x new],[fx 0],'g-');
  if abs(x-new)<presnost
    disp('mame nulu');
    x=new
    i
    break;
  end; 
  x=new;
  
end;     	