home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / modula2 / library / modula1 / recurren.mod < prev    next >
Text File  |  1987-06-11  |  2KB  |  101 lines

  1. (* Compute analytic functions as truncated sums.  Determine
  2.    the recurrence relations of their terms. *)
  3.  
  4. MODULE recurrence;
  5.  
  6. FROM InOut     IMPORT WriteString, WriteLn;
  7. FROM RealInOut IMPORT WriteReal, ReadReal;
  8.  
  9. VAR n: CARDINAL;
  10.     i,x,y,s,t: REAL;
  11.  
  12. BEGIN
  13.   WriteString(' exp'); WriteLn;
  14.   n := 1;
  15.   REPEAT
  16.     ReadReal(x); y := 1.0;
  17.     i := 0.0; t := 1.0;
  18.     REPEAT
  19.       i := i + 1.0;
  20.       t := t*x/i;
  21.       y := y+t;
  22.     UNTIL y+t = y;
  23.     WriteReal(x,9); WriteReal(y,9); WriteReal(i,9);
  24.     DEC(n);
  25.   UNTIL n = 0;
  26.  
  27.   WriteString(' sin'); WriteLn;
  28.   n := 1;
  29.   REPEAT
  30.     ReadReal(x); y := x;
  31.     i := 1.0; s := x*x;
  32.     t := x;
  33.     REPEAT
  34.       i := i + 2.0;
  35.       t := -t*s/((i-1.0)*i);
  36.       y := y + t;
  37.     UNTIL y + t = y;
  38.     WriteReal(x,9); WriteReal(y,9); WriteReal(i/2.0,9);
  39.     DEC(n);
  40.   UNTIL n = 0;
  41.  
  42.   WriteString(' cos'); WriteLn;
  43.   n := 1;
  44.   REPEAT
  45.     ReadReal(x); y := 1.0;
  46.     i := 0.0; s := x*x;
  47.     t := 1.0;
  48.     REPEAT
  49.       i := i + 2.0;
  50.       t := -t*s/((i-1.0)*i);
  51.       y := y + t;
  52.     UNTIL y + t = y;
  53.     WriteReal(x,9); WriteReal(y,9); WriteReal(i/2.0,9);
  54.     DEC(n);
  55.   UNTIL n = 0;
  56.  
  57.   WriteString(' arcsin'); WriteLn;
  58.   n := 1;
  59.   REPEAT
  60.     ReadReal(x); y := x;
  61.     i := 1.0; s := x*x;
  62.     t := x;
  63.     REPEAT
  64.       i := i + 2.0;
  65.       t := t*s*((i-2.0)*(i-2.0))/((i-1.0)*i);
  66.       y := y + t;
  67.     UNTIL y + t = y;
  68.     WriteReal(x,9); WriteReal(y,9); WriteReal(i/2.0,9);
  69.     DEC(n);
  70.   UNTIL n = 0;
  71.  
  72.   WriteString(' arctan'); WriteLn;
  73.   n := 1;
  74.   REPEAT
  75.     ReadReal(x); y := x;
  76.     i := 1.0; s := x*x;
  77.     t := x;
  78.     REPEAT
  79.       i := i + 2.0;
  80.       t := -t*s*(i-2.0)/i;
  81.       y := y + t;
  82.     UNTIL y + t = y;
  83.     WriteReal(x,9); WriteReal(y,9); WriteReal(i/2.0,9);
  84.     DEC(n);
  85.   UNTIL n = 0;
  86.  
  87.   WriteString(' ln'); WriteLn;
  88.   n := 1;
  89.   REPEAT
  90.     ReadReal(x); x := x - 1.0;
  91.     y := x; t := x; i := 1.0;
  92.     REPEAT
  93.       i := i + 1.0;
  94.       t := -t*x*(i-1.0)/i;
  95.       y := y + t;
  96.     UNTIL y + t = y;
  97.     WriteReal(x + 1.0,9); WriteReal(y,9); WriteReal(i,9);
  98.     DEC(n);
  99.   UNTIL n = 0;
  100. END recurrence.
  101.