ocmath_polynomial

 

Description

This function constructs a polynomial curve

Syntax

bool ocmath_polynomial( const double * pX, double * pY, uint nSize, const double * pParas, int nOrder )

Parameters

pX
[input] pointer to X vector data, must have nSize values
pY
[output] pointer to resulting vector data, must have been allocated with nSize values, and they are replaced by the polynomial values for each pX values
nSize
[input] vector size of both pY and pX
pParas
[input] pointer to the vector to hold the polynomial coefficients, P[0], P[1] etc
nOrder
[input] polynomial order, pParas must hold (nOrder + 1) values

Return

Returns TRUE on success and FALSE on failure.

Examples

EX1

void ocmath_polynomial_ex1()
{
    GraphLayer gl = Project.ActiveLayer();
    if(!gl)
        return;
    
    using cc = Project.ActiveCurveBase();
    string strCuvName = cc.GetName();
    if(strCuvName.IsEmpty())
        return;
    
    // First create a copy of the data curve for further processing
    Curve crvDataCopy(cc);
    double coeff[3];
    fitpoly(crvDataCopy, 2, coeff); // fit 2nd order
    
    double x1, x2;
    Curve_MinMax(&crvDataCopy, &x1, &x2, FALSE);
    int npts = 300;
    vector vx;
    vx.Data(x1, x2, (x2-x1)/(npts-1)); 
    vector vy(vx.GetSize());
    ocmath_polynomial(vx, vy, vx.GetSize(), coeff, 2);
    // plot the polynomial with a new hidden wks
    Worksheet wks;
    wks.Create(NULL, CREATE_HIDDEN);
    wks.SetSize(vx.GetSize(), 2);
    DataRange drOut;
    drOut.Add("X", wks, 0, 0, -1, 0);
    drOut.Add("Y", wks, 0, 1, -1, 1);
    drOut.SetData(&vy, &vx);
    int nPlot = gl.AddPlot(drOut, IDM_PLOT_LINE);
    DataPlot dp = gl.DataPlots(nPlot);
    dp.SetColor(1); // red
}

Remark

See Also

header to Include

origin.h

Reference