Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- / calcular numericamente int_{0.1}^{1.0} (1/x)dx = -ln(0.1)
- // calcular pela regra do ponto médio, tendo mais precisão
- #include <stdio.h>
- #include <math.h>
- int main(void)
- {
- int i,n;
- double h,x,sum,val,e;
- for (n=2;n<1e6;n*=2)
- {
- h=(1.0-0.1)/n; // h=delta x!
- sum=0.0; // importante zerar a soma!!!!
- for (i=0;i<n;i++)
- {
- x=0.1+h*(i+1/2.); //lembra desse ponto!!!!
- sum+=h*(1/x);
- }
- val=-log(0.1);
- e=fabs(((val-sum)/val));
- printf("%d\t %e\n",n,e);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement