Advertisement
luizaspan

int_{0.1}^{1.0} (dx/x) IV

May 12th, 2015
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. // calcular numericamente int_{0.1}^{1.0} (dx/x) = -ln(0.1)
  2. // regra do trapézio (mais precisão)
  3.  
  4. #include <stdio.h>
  5. #include <math.h>
  6.  
  7. #define n 100
  8.  
  9. int main (void)
  10. {
  11.   int i;
  12.   double h,x1,x2,soma=0.0f,soma2=0.0f;
  13.  
  14.   h=(1.0-0.1)/n;
  15.  
  16.     for (i=0;i<n;i++)
  17.       {
  18.     x1=0.1+h*i;
  19.     x2=0.1+h*(i+1);
  20.     soma+=0.5*h*(1/x1 + 1/x2);
  21.       }
  22.  
  23.   printf("\nIntegral calculada: %f. Valor real: %f\n\n",soma, -log(0.1));
  24.  
  25.   return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement