M
Manuele Santoprete
I wrote this code basically the trapezoidal rule to compute integrals.
If I compile it with different versions of gcc and run the executable I
get different results. In some cases I get 0.335 that seems the right
result, in other cases I get something close to 2.5.
Any help would be appreciated.
Thanks!!
#include <stdio.h>
#include <math.h>
# define N 11
double Q[]={0,0.01,0.04,0.09,0.16,0.25,0.36,0.49,0.64,0.81,1},
dt[]={0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1};
/*double L[N], h[N];*/
double integral;
double trapzd (double L[N], double h[N-2]);
double S;
int
main(void)
{
integral=trapzd(Q,dt);
printf("%g\n",integral);
return 0;
}
double trapzd (double L[],double h[])
{
int i;
for(i=0;i<=N-2;i++)
{
S=S+0.5*h*(L[i+1]+L);
}
return S;
}
If I compile it with different versions of gcc and run the executable I
get different results. In some cases I get 0.335 that seems the right
result, in other cases I get something close to 2.5.
Any help would be appreciated.
Thanks!!
#include <stdio.h>
#include <math.h>
# define N 11
double Q[]={0,0.01,0.04,0.09,0.16,0.25,0.36,0.49,0.64,0.81,1},
dt[]={0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1};
/*double L[N], h[N];*/
double integral;
double trapzd (double L[N], double h[N-2]);
double S;
int
main(void)
{
integral=trapzd(Q,dt);
printf("%g\n",integral);
return 0;
}
double trapzd (double L[],double h[])
{
int i;
for(i=0;i<=N-2;i++)
{
S=S+0.5*h*(L[i+1]+L);
}
return S;
}