# NumericIntegration

Advanced Analysis Library Only

AnalysisLibErrType NumericIntegration (double inputArray[], int size, double dt, int integrationMethod, double *integrationResult);

## Purpose

Performs numeric integration on the data the input array x contains using one of the following four numeric integration methods: Trapezoidal Rule, Simpson's Rule, Simpson's 3/8 Rule, or Bode Rule. You normally obtain the data to integrate by sampling some function f(t) at multiples of dt. Your samples are f(0), f(dt), f(2dt), and so on. dt is the sampling step size.

If you do not provide a sufficient number of points for the integration method you choose, NumericIntegration applies the method you choose to all points it can. For the points that remain, NumericIntegration uses the next possible lower-order method.

For example, if you choose Bode Rule as the integration method, the following table shows how NumericIntegration evaluates the integral for different numbers of data points. If you provide 224 points and choose the Bode Rule method, NumericIntegration arrives at the result by performing 55 Bode Rule method partial evaluations and one Simpson's 3/8 Rule method evaluation.

Number of Points | Partial Evaluations Performed
224 | 55 Bode, 1 Simpson's 3/8
225 | 56 Bode
226 | 56 Bode, Trapezoidal
227 | 56 Bode, 1 Simpson's
228 | 57 Bode, 1 Simpson's 3/8

Formulas for Integration Methods

For i = 0, 1, 2, . . ., int((n — 1)/k), where n is the number of data points, k is an integer dependent on the method, and x is the input array. The following shows the basic formulas for each of the four integration methods.

Trapezoidal Rule:

(dt/2) × (xi + xi + 1) for k = 1

Simpson's Rule

(dt/3) × (x2i + 4x2i + 1 + x2i + 2) for k = 2

Simpson's 3/8 Rule

(dt/8) × (3x3i + 9x3i + 1 + 9x3i + 2 + 3x3i + 3) for k = 3

Bode Rule

(dt/45) × (14x4i + 64x4i + 1 + 24x4i + 2 + 64X4i + 3 + 14x4i + 4) for k = 4

Each method depends on the sampling interval, dt, and calculates the integral by using successive applications of the basic formula to perform partial evaluations. The number of points each partial evaluation uses represents the order of the method. The result is the sum of these successive partial evaluations.

## Parameters

Input
Name | Type | Description
inputArray | double-precision array | Array that contains data to integrate. This data is obtained by sampling a function f(t) at multiples of dt, that is, f(0), f(dt), f(2dt), and so on.
size | integer | Number of elements in inputArray.
dt | integer | Interval size, which represents the sampling step size to use to obtain the data.
integrationMethod | integer | Integration method used to perform the numeric integration. The following table shows valid integrationMethod values.
integrationMethod | Value
Trapezoidal Rule | 0
Simpson's Rule | 1
Simpson's 3/8 Rule | 2
Bode Rule | 3
Output
Name | Type | Description
integrationResult | double | Result of the numeric integration.

## 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.