CWenger
07-31-2004, 01:35 PM
I must be missing something obvious (remember it's been 2 years since I finished my college calculus ;)), but the trapzd numerical integration function always seems to return half of the true answer. I am just trying simple functions, such as y=x, for testing purposes. I have retyped the entire funtion twice and I am sure it does not have any typos. Here is an example code of calling the function, which is so simple I don't think I could be screwing it up:
int main()
{
printf("x,{x,0,5}=%f\n",trapzd(yeqx,0,5,10));
return(0);
}
float yeqx(float x)
{
return(x);
}
The function returns 6.25, although it should be 25/2=12.5.
int main()
{
printf("x,{x,0,5}=%f\n",trapzd(yeqx,0,5,10));
return(0);
}
float yeqx(float x)
{
return(x);
}
The function returns 6.25, although it should be 25/2=12.5.