program NEWTONRF(printer);
uses printer;
var
   I,N    :integer;
   XO,XI,Y,TOL,ERRO    :real;
   NOMEFUN  : string[30];

function FUNCAO(X :real) : real;
begin
  FUNCAO := Sin(X)/Cos(X) - X - 1.0
end;

function DERFUN(X :real) : real;
begin
  DERFUN := 1.0/(Cos(X)*Cos(X)) - 1.0
end;

begin
  writeln(Lst,' Metodo de Newton-Raphson ');writeln(Lst);
  writeln(Lst,' Equacao a ser resolvida ');
  NOMEFUN := ' Tan(X) - X - 1.0 = 0 ';
  writeln(Lst,'  ',NOMEFUN);writeln(Lst);
  writeln(' Entre com a estimativa inicial, a tolerancia e o numero maximo de iteracoes ');
  write('XO = ');readln(XO);
  write('Tol = ');readln(Tol);
  write('N = ');readln(N);
  writeln(Lst,' Estimativa inicial = ',XO:5:2,'  Num.Max. = ',N:4,
  '  Tolerancia = ',TOL:8:5);writeln(Lst);
  I := 0;
  repeat
  XI := XO-FUNCAO(XO)/DERFUN(XO);
  writeln(Lst,' XO = ',XO:8:5,'   XI = ',XI:8:5);
  ERRO := ABS(XI-XO);
  XO := XI;
  I := I + 1;
  until (ERRO < TOL) or (I > N);
  if I > N then writeln(Lst,' Nao convergiu com ',N:2,' iteracoes ')
           else Begin   writeln(LST,' A raiz e ',XI:8:5);
           writeln(Lst,' Nesse ponto a funcao vale ',FUNCAO(XI):12:9)
                end;
           writeln(Lst)
end. { fim do NEWTONRF }



