A structure that approximates the definite integral of a function over a finite interval.
The following code is an example of using a `Quadrature` structure to calculate the
area under a curve defined by `y = sqrt(radius * radius - pow(x - radius, 2))`:
let quadrature = Quadrature(integrator: .qags(maxIntervals: 10),
absoluteTolerance: 1.0e-8,
relativeTolerance: 1.0e-2)
let result = quadrature.integrate(over: 0.0 ... 25.0) { x in
let radius: Double = 12.5
return sqrt(radius * radius - pow(x - radius, 2))
}
switch result {
case .success(let integralResult, let estimatedAbsoluteError):
print("quadrature success:", integralResult,
estimatedAbsoluteError)
case .failure(let error):
print("quadrature error:", error.errorDescription)
}
Alternatively, you can integrate over a function that uses vectors for its
source and destination. For example:
func vectorExp(x: UnsafeBufferPointer<Double>,
y: UnsafeMutableBufferPointer<Double>) {
let radius: Double = 12.5
for i in 0 ..< x.count {
y[i] = sqrt(radius * radius - pow(x[i] - radius, 2))
}
}
let vRresult = quadrature.integrate(over: 0.0 ... diameter,
integrand: vectorExp)
Initializes and returns a quadrature instance.
- Parameter integrator: An enumeration specifying the integration algorithm and relevant properties.
- Parameter absoluteTolerance: Requested absolute tolerance on the result.
- Parameter relativeTolerance: Requested relative tolerance on the result.
get · iOS 13.0+
absoluteTolerance
TypeScript
get absoluteTolerance(): number
Swift declaration
var absoluteTolerance: Double { get set }
The quadrature instance's requested absolute tolerance on the result.
set · iOS 13.0+
absoluteTolerance
TypeScript
set absoluteTolerance(value: number)
Swift declaration
var absoluteTolerance: Double { get set }
The quadrature instance's requested absolute tolerance on the result.
get · iOS 13.0+
relativeTolerance
TypeScript
get relativeTolerance(): number
Swift declaration
var relativeTolerance: Double { get set }
The quadrature instance's requested relative tolerance on the result.
set · iOS 13.0+
relativeTolerance
TypeScript
set relativeTolerance(value: number)
Swift declaration
var relativeTolerance: Double { get set }
The quadrature instance's requested relative tolerance on the result.
Performs the integration over the supplied function.
- Parameter interval: The lower and upper bounds of the integration interval.
- Parameter integrand: The function to integrate. The input value is `x` that's within the interval over which the integrand is being integrated, and the output value is the corresponding value `y = integrand(x)` at those points.
Skipped declarations
1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.