Advertisement
luizaspan

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

May 12th, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. // calcular numericamente int_{0.1}^{1.0} (dx/x) = -ln(0.1)
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. #define n 1000
  7.  
  8. int main (void)
  9. {
  10.   int i;
  11.   double h,x,soma=0.0f; // esse f não dá problema
  12.  
  13.   h=(1.0-0.1)/n;
  14.  
  15.     for (i=0;i<n;i++)
  16.       {
  17.     x=0.1+h*i;
  18.     soma+=h*(1/x);
  19.       }
  20.  
  21.   printf("\nIntegral calculada: %f. Valor real: %f\n\n",soma, -log(0.1));
  22.  
  23.   return 0;
  24. }
  25.  
  26. // o valor da integral foi estimado acima do seu valor real.
  27. // int_{x_{i}}^{x_{i+1}} f(x)dx = h*f_{i+1}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement