Advertisement
luizaspan

(TAREFA 3) Int II

May 14th, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. / calcular numericamente int_{0.1}^{1.0} (1/x)dx = -ln(0.1)
  2. // calcular pela regra do ponto médio, tendo mais precisão
  3.      
  4. #include <stdio.h>
  5. #include <math.h>
  6.      
  7. int main(void)
  8. {
  9.   int i,n;
  10.   double h,x,sum,val,e;
  11.      
  12.   for (n=2;n<1e6;n*=2)
  13.     {
  14.      
  15.       h=(1.0-0.1)/n; // h=delta x!
  16.       sum=0.0; // importante zerar a soma!!!!
  17.      
  18.       for (i=0;i<n;i++)
  19.     {
  20.       x=0.1+h*(i+1/2.); //lembra desse ponto!!!!
  21.       sum+=h*(1/x);
  22.     }
  23.      
  24.       val=-log(0.1);
  25.       e=fabs(((val-sum)/val));
  26.      
  27.       printf("%d\t %e\n",n,e);
  28.     }
  29.      
  30.      
  31.   return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement