# Curve_derivative

## Description

Create the n-th Order derivative of a source curve with optional weighting.

## Syntax

int Curve_derivative( curvebase * pcrvData, curvebase * pcrvResults, int nOrder = 1, double dSmoothness = BSPLN_OFF, Dataset * pdsWeights = NULL )


## Parameters

pcrvData
[input] source curve
pcrvResults
[output] result curve
nOrder
[input] The order of the derivative
dSmoothness
[input] Smoothness factor can be any arbitrary value >= 0 or a predefined constant
(BSPLN_AUTO, BSPLN_INTERPOLATE and BSPLN_WEIGTHED_LEAST_SQUARE_POLYNOMIAL, BSPLN_OFF)
enumerated in OC_const.h. The enumerated constants are negative numbers to distinguish them from arbitrary smoothness factors.
pdsWeights
[output] Dataset containing weights for the input curve. If not NULL the number of points in the weight data set must equal the number of points in the source curve. The default weighting is 1 for all points.
if dSmoothness equals BSPLN_OFF, only the first order derivative will be calculated.

## Return

Returns zero on successful exit and a non-zero error code on failure.

Errors:

-1=System can not allocate enough memeory

-2=Curve data type error

-4=The result curve range can not be set

5=The smoothness parameter must be equal to or greater than 0

11=The number of data points is less than 4

63=The sequence of X in source data is not increasing

73=Memory allocation failed

240=The weights are not all positive

254=The smoothness parameter is too small

## Examples

EX1

// This is a self contained sample program for the function Curve_derivative,
// Its sample data is created at the beginning of the program.
// To run the program, enter the following command in the Script window:
//   Curve_derivative_ex1
// It returns a message like the following line:
//   Derivation Succeeded: Data4_B==>DerivY, Order=1, Smoothness=1

void Curve_derivative_ex1()
{
string wksName,colNameInY,colNameOutY;
Column myColInY, myColOutY;
double dSmoothness;
int nOrder, rc;

Worksheet wks;
wks.Create();
wksName=wks.GetPage().GetName();
Dataset myInXDs(wks,0);
Dataset myInYDs(wks,1);

//******* Create sample data *****************
myInXDs.SetSize(7);
myInYDs.SetSize(7);
myInXDs[0]=1;    myInYDs[0]=0.097;
myInXDs[1]=2;    myInYDs[1]=0.41256;
myInXDs[2]=3;    myInYDs[2]=0.24909;
myInXDs[3]=4;    myInYDs[3]=0.47304;
myInXDs[4]=5;    myInYDs[4]=0.2476;
myInXDs[5]=6;    myInYDs[5]=0.64529;
myInXDs[6]=7;    myInYDs[6]=0.44514;
//******** End of Sample Data Creation *******

wks.Columns(2).SetType(OKDATAOBJ_DESIGNATION_X);

myColInY.Attach(wks,1);
myColInY.GetName(colNameInY);
myColOutY.Attach(wks,3);
myColOutY.GetName(colNameOutY);

Curve crvData(wks,0,1);
Curve crvResults(wks,2,3);

nOrder=1;
dSmoothness=1.0;
rc = Curve_derivative(&crvData, &crvResults, nOrder, dSmoothness); // Demonstration of Curve_derivative

if(rc==0)
printf("Derivation Succeeded: %s_%s==>%s, Order=%d, Smoothness=%g\n",
wksName,colNameInY,colNameOutY,nOrder,dSmoothness);
else
printf("Derivation Failed. Error Code=%d\n",rc);
}


## Remark

Create the n-th Order derivative of a source curve with optional weighting.

The resulting derivative curve will copy the source X data set if an empty X data set is provided or it will use a specified X data set as long as the range is within the source X range.

Please note that in Origin 7.0, the default argument dSmoothness was BSPLN_AUTO, but from 7.5, it was changed to BSPLN_OFF.