home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / raytrace / radiance / cal / root.cal < prev    next >
Encoding:
Text File  |  1991-04-23  |  472 b   |  25 lines

  1. {
  2.     root.cal - calculate zeroes of functions using Newton's method.
  3.  
  4.     2/3/88
  5. }
  6.  
  7. FTINY : 1e-12;
  8.  
  9. root(f, x0) = root2(f, x0, x0-f(x0)/lim(f1(f,x0)), nit);
  10.  
  11. root2(f, x0, x1, i) = if(i,
  12.             if(err-abs(x1-x0),
  13.                 x1,
  14.                 root2(f,x1,x1-f(x1)/lim(f1(f,x1)),i-1)),
  15.             0);
  16.  
  17. abs(x) = if(x, x, -x);
  18. lim(x) = if(x, max(x,err), -max(-x,err));
  19. max(a,b) = if(a-b, a, b);
  20.  
  21. f1(f,x) = (f(x+FTINY)-f(x-FTINY))/FTINY/2;    { numerical derivative }
  22.  
  23. err = 1e-6;
  24. nit = 100;
  25.