Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define N 1000
- double f(double x)
- {
- return 1/x;
- }
- int main(void)
- {
- int i;
- double h,soma=0.0f;
- h=(1.0-0.1)/N;
- for (i=0;i<N;i++)
- {
- double x = 0.1 + h*i;
- soma += h*f(x);
- }
- double e = fabs((-log(0.1)-soma)/-log(0.1));
- printf("Valor calculado: %.15e \nValor real: %.15e \n",soma,-log(0.1));
- printf("Erro: %e % \n",e*100);
- return 0;
- }
- // I(a,b) = h*sum_i ( f(x_i) )
- // erro = h/2 * [f(b)-f(a)]
- // erro ~ 1/N
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement