clc
clearvars

f = @(x) exp(x)-3*x^2; % introducem functia
fp = @(x) exp(x)-6*x; % introducem derivata functiei
x0 = 0.9; % alegerea aproximatiei initiale
tol = 1e-6; % definirea tolerantei

N = 1000;  % numarul maxim de iteratii
x(1) = x0;
n = 2; 
nfinal = N + 1; 
iter = 1;
fprintf ( ' Nr. iteratie     x(i)                |x(i) - x(i-1)| \n');     
fprintf('   \n');
while (n <= N + 1)
  fe = f(x(n - 1));
  fpe = fp(x(n - 1));
  x(n) = x(n - 1) - fe/fpe;
  if abs(x(n)-x(n-1))<= tol
    nfinal = n; 
    fprintf(' %3.0f        %4.16f      %4.16f \n ', iter,x(n),abs(x(n)-x(n-1)));
    rad=x(n);
    break;
  end
  
       
  
  fprintf(' %3.0f        %4.16f      %4.20f \n ', iter,x(n),abs(x(n)-x(n-1)));
  rad=x(n);
  
  %printf('iteratia : ');
  %disp(iter);
  %printf('valoarea : ');
  %disp(x(n));
  iter = iter + 1;
  n = n + 1;

end

%disp(f);
disp (' ');
fprintf(' Solutia ecuatiei in toleranta de calcul ceruta = %4.16f \n ', rad);
disp (' ');
fprintf(' Verificarea solutiei obtinute f(radacina)= %4.20f \n', f(rad));
disp (' ');
%disp(x(n));