home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / PAS_ENG.ZIP / NEWDR.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-07-19  |  621 b   |  38 lines

  1. program newdr; { -> 243 }
  2. var x,x2 : real;
  3.  alldone : boolean;
  4.  error : boolean;
  5.  
  6.  
  7. procedure func(x: real;
  8.   var fx,dfx: real);
  9. begin
  10.   fx:=x*x-2.0;
  11.   dfx:=2.0*x
  12. end; { func }
  13.  
  14. procedure newton(var x: real);
  15. const  tol = 1.0E-6;
  16.  
  17. var fx,dfx,dx,x1: real;
  18.  
  19. begin { newton }
  20.   repeat
  21.     x1:=x;
  22.     func(x,fx,dfx);
  23.     dx:=fx/dfx;
  24.     x:=x1-dx;
  25.     writeln('x=',x1,'  fx=',fx,'  dfx=',dfx);
  26.   until abs(dx)<=abs(tol*x)
  27. end; { newton }
  28.  
  29. begin  { main program }
  30.   clrscr;
  31.   writeln;
  32.   x:=2.0; { first guess }
  33.   newton(x);
  34.   writeln;
  35.   writeln(chr(7),'The solution is ',x);
  36.   writeln
  37. end.
  38.