# Difference

Advanced Analysis Library Only

AnalysisLibErrType Difference (double inputArray[], int numberOfElements, double samplingInterval, double initialCondition, double finalCondition, double outputArray[]);

## Purpose

Finds the discrete difference of the input array. Difference obtains the element of the resulting array using the following formula:

where | X–1 is the initial condition
| Xn is the final condition

Difference can perform the operation in place; that is, the input and output arrays can be the same.

### Example

/* Generate an array with random numbers and differentiate it. */
double x[200], y[200];
double dt, xInit, xFinal;
int n;
n = 200;
dt = 0.001;
xInit = -0.5;
xFinal = -0.25;
Uniform (n, 17, x);
Difference (x, n, dt, xInit, xFinal, y);

## Parameters

Input
Name | Type | Description
inputArray | double-precision array | Input array to differentiate.
numberOfElements | integer | Number of elements to include in the differentiation.
samplingInterval | double-precision | Sampling interval used in the differentiation of the input array. Default Value: 1.0.
initialCondition | double-precision | Initial condition. When the differentiation formula is applied to each array element, the value of the preceding array element is used. initialCondition specifies the value preceding the first element of the input array. In other words, initialCondition can be thought of as the value of X–1. Default Value: 0.0.
finalCondition | double-precision | Final condition. When the differentiation formula is applied to each array element, the value of the next array element is used. finalCondition specifies the value following the last element of the input array. In other words, finalCondition can be thought of as the value of Xn. Default Value: 0.0.
Output
Name | Type | Description
outputArray | double-precision array | Differentiated array.

## Return Value

Name | Type | Description
status | AnalysisLibErrType | A value that specifies the type of error that occurred. Refer to analysis.h for definitions of these constants.