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,a=0.1;
- h=(1.0-a)/N;
- for (i=0;i<N;i++)
- {
- double x1 = a + h*i, x2= a + h*(i+1);
- soma += (h/2)*(f(x1) + f(x2));
- }
- double e = fabs((-log(a)-soma)/-log(a));
- printf("Valor calculado: %.15e \nValor real: %.15e \n",soma,-log(a));
- printf("Erro: %e % \n",e*100);
- return 0;
- }
- // erro = 1/12 * h^2 * [f'(a) - f'(b)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement