Function

quadrature_integrate(_:_:_:_:_:_:_:_:)

Computes an approximation to the definite integral of a function on a specified interval.

Declaration

func quadrature_integrate(_ __f: UnsafePointer<quadrature_integrate_function>, _ __a: Double, _ __b: Double, _ options: UnsafePointer<quadrature_integrate_options>, _ status: UnsafeMutablePointer<quadrature_status>?, _ abs_error: UnsafeMutablePointer<Double>?, _ workspace_size: Int, _ workspace: UnsafeMutableRawPointer?) -> Double

Parameters

__f

Pointer to a struct of type quadrature_integrate_function, defined in integration.h. The struct contains a pointer to the integration callback described in the previous chapter, and a pointer that will be passed as the first parameter to the integration callback

__a

Value of type double for the first bound of the integration interval; need not be <= __b. If the chosen algorithm is QAGS, this may be +INFINITY or -INFINITY.

__b

Value of type double for the second bound of the integration interval; need not be >= __a. If the chosen algorithm is QAGS, this may be +INFINITY or -INFINITY.

options

Pointer to a struct of type quadrature_integrate_options, defined in integration.h. The integration options control the logic of the integration as described in the previous chapter.

status

Pointer to a variable of type quadrature_status, an enum type defined in Quadrature.h, or NULL. If not NULL, the variable will contain the status of the integration after the function returns. The defined values for the status are given below under “Return value.”

abs_error

Pointer to a variable of type double, or NULL. If not NULL, the variable will contain the estimated absolute error in the result after the function returns.

workspace_size

Value of type size_t; the size of the workspace you are supplying. Ignored if you are not supplying a workspace.

workspace

Pointer to a workspace area you have allocated, or NULL.

Return Value

The function returns the result of the quadrature operation, of type double.

It also stores the status in the variable whose address was passed as the status parameter. The defined status constants are:

  • QUADRATURE_SUCCESS = 0: Success.

  • QUADRATURE_ERROR = -1: Generic error.

  • QUADRATURE_INVALID_ARG_ERROR = -2: Invalid argument.

  • QUADRATURE_ALLOC_ERROR = -3: Memory allocation failed.

  • QUADRATURE_INTERNAL_ERROR = -99: This is a bug in the Quadrature code, please file a bug report.

  • QUADRATURE_INTEGRATE_MAX_EVAL_ERROR = -101: The requested accuracy limit could not be reached with the allowed number of evals/subdivisions.

  • QUADRATURE_INTEGRATE_BAD_BEHAVIOUR_ERROR = -102: Extremely bad integrand behavior, or excessive roundoff error occurs at some points of the integration interval.

Discussion

On success, the absolute difference between the result S and the mathematically exact definite integral is assumed to be less than max(abs_tolerance, rel_tolerance * abs(S)).

The integration algorithms will identify most cases of divergence, slow convergence, and bad behavior, and report an error. You should always check the returned status and absolute error before assuming that the result is valid.

See Also

Quadrature

struct Quadrature

A structure that approximates the definite integral of a function, over a finite interval.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software