Advertisement
luizaspan

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

May 12th, 2015
331
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. // ponto médio!! (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,x,soma=0.0f;
  13.  
  14.   h=(1.0-0.1)/n;
  15.  
  16.     for (i=0;i<n;i++)
  17.       {
  18.     x=0.1+h*(i+1/2.); //i+1, não somente i
  19.     // repara esse ponto!!
  20.     soma+=h*(1/x);
  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