ocmath_simple_math

 

Description

Perform arithmatic operation element-wised on two curves

Syntax

int ocmath_simple_math( UINT nSize, double * pX, double * pY, UINT nSrcSize1, const double * pSrcX1, const double * pSrcY1, UINT nSrcSize2, const double * pSrcX2, const double * pSrcY2, int nOperator = MATHTOOL_OPT_ADD, int nRange = MATHTOOL_RNG_CUV, int nMethod = INTERP_TYPE_LINEAR, double dSmoothingFactor = 0 )

Parameters

nSize
[input] the size of result curve
pX
[output] pointer to the x coordinates of result curve
pY
[output] pointer to the y coordinates of result curve
nSrcSize1
[input] the size of the first curve
pSrcX1
[input] pointer to the x coordinates of the first curve
pSrcY1
[input] pointer to the y coordinates of the first curve
nSrcSize2
[input] the size of the second curve
pSrcX2
[input] pointer to the x coordinates of the second curve
pSrcY2
[input] pointer to the y coordinates of the second curve
nOperator
[input] the operation between the two input curve
MATHTOOL_OPT_ADD add operation
MATHTOOL_OPT_SUB subtract operation
MATHTOOL_OPT_DIV divide operation
MATHTOOL_OPT_MUL multiply operation
MATHTOOL_OPT_EXP exponent operation
nRange
[input] the range to perform the operation on
MATHTOOL_RNG_CUV perform the operation on entire curves
MATHTOOL_RNG_COM perform the operation on common x coordinates
MATHTOOL_RNG_UD reserved for future
nMethod
[input] interpolating method, only available when use MATHTOOL_RNG_CUV.
INTERP_TYPE_LINEAR(linear interpolation),
INTERP_TYPE_SPLINE(cubic spline interpolation with not-a-knot boundary condition, and the not-a-knot boundary condition assume that the 3rd order derivative are continuous on the 2nd and last 2nd points),
INTERP_TYPE_BSPLINE(B-Spline curve fitting using method by Dierckx.P)
dSmoothingFactor
[input] This argument specifies the closeness to the original data, only available when nMethod = INTERP_TYPE_BSPLINE. dSmoothingFactor >= 0.
By means of this parameter, the user can control the tradeoff between closeness of fit and smoothness of fit of the approximation.
If dSmoothingFactor is too large, the spline will be too smooth and signal will be lost ; if it is too small the spline will pick up too much noise.
In the extreme cases the program will return an interpolating spline if dSmoothingFactor=0 and the weighted least-squares polynomial of degree 3 if s is very large.

Return

Return OE_NOERROR if succeed, otherwise, non-zero error code is returned.

Examples

EX1

//Assume there is a workbook named "Book1" in the current project
void ocmath_simple_math_ex1()
{
    Worksheet wks("Book1");
    vector vA, vB, vC;
    
    vA.Data(0.0, 6.0, 0.03);
    int iCount = vA.GetSize();
    vB.SetSize(iCount);
    vC.SetSize(iCount);
    
    for( int ii=0; ii<iCount; ii++ )
    {
        vB[ii] = sin(vA[ii]);
        vC[ii] = cos(vA[ii]);
    }

    Dataset dsX(wks, 0);
    Dataset dsY(wks, 1);

    dsX.SetSize(iCount);
    dsY.SetSize(iCount);
    vector vx(iCount);
    vector vy(iCount);
    ocmath_simple_math(iCount, vx, vy, iCount, vA, vB, iCount, vA, vC, MATHTOOL_OPT_ADD);
    dsX = vx;
    dsY = vy;
}

Remark

See Also

Header to Include

origin.h

Reference