Advertisement
bugaevc

Integral Calculation

Nov 22nd, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. double integral(double a, double b, int n)
  6. {
  7.     double h = (b-a) / n;
  8.     double sum = 0;
  9.     double x;
  10.     for(x = a; x <= b; x++)
  11.         sum += cos(exp(x)); // или как там посчитать это значение
  12.     return sum * h;
  13. }
  14.  
  15. int main(void)
  16. {
  17.     double a = 0.25, b = 2.76; // Смотри, вот переменные близки по смыслу — я написал их в одной строке
  18.     int n = 1;
  19.     double old_integral, new_integral = integral(a, b, n);
  20.     do
  21.     {
  22.         old_integral = new_integral;
  23.         n *= 2;
  24.         new_integral = integral(a, b, n);
  25.     }
  26.     while(fabs(old_integral-new_integral) > 0.0001);
  27.     printf("%lf", new_integral);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement