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=1;i<=N-1;i+=2)
- {
- double x1,x2,x3; // ou definir apenas x=a+h*i e em x1 -> x-h, x2 -> x+h
- x1=a+h*(i-1);
- x2=a+h*(i);
- x3=a+h*(i+1);
- soma += (1./3)*h*(f(x1)+4*f(x2)+f(x3));
- }
- 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/90 * h^4 * [f'''(a) - f'''(b)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement