2.1.17.2.2.6 Curve_yfromX


Description

Get interpolated/extrapolated Y value of Curve at specified X value.

Syntax

double Curve_yfromX( curvebase * pcrvData, double dX )

Parameters

pcrvData
[input] Pointer to Curve
dX
[input] Value of X

Return

For given Curve returns interpolated/extrapolated value of Y at specified value of X.

Since the function uses extrapolation/interpolation, the out-of-range error will not occur.

Examples

EX1

// This is a self contained sample program for the function Curve_xfromY, 
// Its sample data is created at the beginning of the program. 
// To run the program, enter the following command in the Script window:
//   Curve_yfromX_ex1
// It returns like the following two lines, one for interpolation, and the 
// other for extrapolation:
//  Find Y at x=3.000000 ==> FOUND: y=6.000000
//  Find Y at x=10.000000 ==> FOUND: y=20.000000
void Curve_yfromX_ex1()
{
    double dYfromX, dX;
    Worksheet wks;
    wks.Create();
    Dataset myXDs(wks,0);
    Dataset myYDs(wks,1);
    
    //******* Create sample data *****************
    myXDs.SetSize(4);
    myYDs.SetSize(4);
    myXDs[0]=1;    myYDs[0]=2;
    myXDs[1]=2;    myYDs[1]=4;
    myXDs[2]=4;    myYDs[2]=8;
    myXDs[3]=8;    myYDs[3]=16;
    //******** End of Sample Data Creation *******
    
    Curve crvData( myXDs, myYDs );    // Create Curve object

    // CASE-1 Interpolation
    dX=3.0;
    dYfromX = Curve_yfromX(&crvData,dX);    // Demonstartion of Curve_yfromX
    printf( "Find Y at x=%f ==> FOUND: y=%f\n",dX,dYfromX);
    
    // CASE-2 Extrapolation
    dX=10.0;
    dYfromX = Curve_yfromX(&crvData,dX);    // Demonstartion of Curve_yfromX
    printf( "Find Y at x=%f ==> FOUND: y=%f\n",dX,dYfromX);    
}

Remark

The function used for fitting function parameter initialization.

See Also

Curve_xfromY

Header to Include

origin.h

Reference