Citation :
#include <math.h>
#include <stdio.h>
#define EPS 0.000001
#define ETA 0.01
#define sqr(x) (x)*(x)
double derx(double(*pf)(double), double x)
{
double val;
val=((*pf)(x+ETA)-(*pf)(x-ETA))/(2*ETA);
return val;
}
double f(double x)
{
double val;
val=exp(-x)*sin(x);
return val;
}
double integr(double(*pf)(double),double a,double b, int n)
{
double pas, som;
int i;
pas=fabs((b-a))/n;
som=0.5*(f(a)+f(b));
for (i=1;i<n;i++)
{
som+=f(a+i*pas);
// printf("pas %g\n",n);
// printf("i= %g\n",i);
}
return som*pas;
}
// double f(double x) {return x*x;}
void main()
{
double x,y,a,b;
int n,j;
FILE *G;
printf("entrer l'intervalle d'integration\n" );
scanf("%lf %lf",&a,&b);
printf("entrer le nombre de pas\n" );
scanf("%d",&n);
printf("pas %g\n",n);
G=fopen("conv.res","w" );
for(j=1;j<n;j++)
{
y=integr(f,a,b,j);
fprintf(G,"%g %g\n",j,y);
}
// printf("l'integrale entre %g et %g vaut %g\n",a,b,y);
fclose(G);
scanf("%lf",&x);
}
|