function [y,it]=newton_reseni(df,ddf,x0,tol)

%[y,it]=newton_reseni(df,ddf,x0,tol)
%
% Zakladni Newtonova metoda pro minimalizaci fce f(x)
%
%  y   ... minimum
%  it  ... pocet iteraci
%
%  df	... gradient minimalizovane fce f(x) 
%  ddf ... Hessian minimalizovane fce f(x) 
%  x0  ... pocatecni iterace
%  tol ... presnost reseni

it=0;
x=x0;
grad=feval(df,x);
Hess=feval(ddf,x);

while norm(grad)>tol  %norm(fxn-fx) >= tol %norm(xn-x) >= tol 
  it=it+1;
  h=-Hess\grad;
  x=x+h;
  grad=feval(df,x);
  Hess=feval(ddf,x);
end;

y=x;

% konec