Advertisement
Ladies_Man

#ARCH_is it KaHaN?

Jan 28th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <math.h>
  3. #include <locale.h>
  4. #include <stdio.h>
  5.  
  6. FILE *file;
  7.  
  8. double f( double x )
  9. {
  10.     return
  11. }
  12.  
  13. double F( double x )
  14. {
  15.     return
  16. }
  17.  
  18. double err = 0.0;
  19.  
  20. double Integral( double Left, double Right, long N, double (*func)(double) )
  21. {
  22.     int i;
  23.     double x, dx, res = 0.0;
  24.     dx = (Right - Left) / N;
  25.     x = Left + dx;
  26.  
  27.     for ( i = 0; i < N; i++) {
  28.         x = Left + (i + 1) * dx;
  29.         double y = (func(x) + func(x + dx)) / 2 - err;
  30.         double t = res + y;
  31.         err = (t - res) - y;
  32.         res = t;
  33.     }
  34.     res *= dx;
  35.     return res;
  36. }
  37.  
  38.  
  39. int main ()
  40. {
  41.     long n;
  42.     double L = 0.0, R = 0.0;
  43.     file = fopen ("archres_KAHAN.csv", "w");
  44.  
  45.     double V, V0 = F(R) - F(L);
  46.     setlocale ( LC_ALL, "");
  47.     fprintf (file, "Num of steps;Relative Mistake;Evaluation of Mistake\n");
  48.  
  49.     for (n = 1; n < 100; n += n/50 + 1) {
  50.         V = Integral( L, R, n, f );
  51.         fprintf (file, "%ld;=%.15G;=%.15G\n", n, (V-V0)/V0,
  52.                // (((R-L)*(R-L)*(R-L)*(pow(10, 10)))/(12.*n*n))/V0 );
  53.  
  54.     }
  55.  
  56.     fclose(file);
  57.     return 0;
  58. }
  59. //for ( x = Left, i = 0; i < N; x+= dx, i++) {
  60. //for ( x = Left; x < Right; x += dx) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement