2.1.17.4.4 ocmath_numeric_integral


Description

This function performs incomplete integral from pxData[0] to x. If x is found in pxData, the function calls ocmath_integrate; otherwise linear interpolation is used to find integral result.

Syntax

int ocmath_numeric_integral( double x, double * py, uint npts, const double * pxData, const double * pyData )

Parameters

x
[input] The upper limit of incomplete integral.
py
[output] pointer to integral result.
npts
[input] Number of points in input data array.
pxData
[input] X data of input data array.
pyData
[input] Y data of input data array.

Return

Returns OE_NOERROR if succeed, otherwise returns error codes:

OE_NULL_POINTER: py, pxData, pyData is NULL.

OE_SIZE_LT: npts must be larger than 1.

OE_NOT_STRICTLY_INCREASING: pxData must be monotonically increasing.

OE_UNDERFLOW: x is smaller than the minimum of pxData.

OE_OVERFLOW: x is larger than the maximum of pxData.

Examples

EX1

void ocmath_numeric_integral_ex1(double x)
{
    GraphLayer gl = Project.ActiveLayer();
    if (!gl)
    {
        out_str("Active layer is not a graph.");
        return;
    }
    
    DataPlot dp = gl.DataPlots(0);                
    DataRange dr;
    vector vx, vy;
    if(dp.GetDataRange(dr))
    {
        DWORD dwPlotID;
        if(dr.GetData(DRR_GET_DEPENDENT | DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vy, &vx) < 0)
        {
            printf("get data failed GetData");
            return;
        }
    }
    
    double y;
    int nRet = ocmath_numeric_integral(x, &y, vx.GetSize(), vx, vy);
    if (nRet != OE_NOERROR)
    {
        printf("Error occurs!\n");
    }
    else
    {
        printf("Integral result: %f\n", y);
    }
}

Remark

See Also

ocmath_integrate, ocmath_2d_integrate

Header to Include

origin.h

Reference