This function is so complicated, I have no better idea. Instead of writing code to implement the trapezoidal rule, may be you can use the ocmath_integrate function to calculate the integrated results, .
For example, this code will integrate the function

void test()
{
// Integral steps
int nSize = 101;
// Vector to save the x, y value of the curve
vector vx(nSize);
vector vy(nSize);
// Vector to save the cumulative integral results
vector vInteg(nSize);
// Construct the X value of the curve
vx[0] = -1.0;
for(int i = 1; i < nSize; i++)
{
vx[i] = vx[i-1] + 0.02;
}
// Construct the Y value of the curve
vy = exp(vx);
IntegrationResult result;
// Perform integration using trapezoidal method.
int nRet = ocmath_integrate(vx, vy, 0, nSize-1, &result, vInteg);
double px = 0;
double py;
// Get the cumulative result at X=0
int iRet = ocmath_interpolate(&px, &py, 1, vx, vInteg, nSize);
}
Thanks
Larry
OriginLab Technical Services
Edited by - larry_lan on 02/24/2008 01:17:15 AM