evaluatePolynomial(usingCoefficients:withVariables:)
Returns a double-precision evaluated polynomial using specified coefficients and variables.
Declaration
static func evaluatePolynomial<U>(usingCoefficients coefficients: [Double], withVariables variables: U) -> [Double] where U : AccelerateBuffer, U.Element == DoubleParameters
- coefficients:
An array that contains the coefficients.
- variables:
An array that contains the independent variables.
Mentioned in
Discussion
For example, the following code evaluates the polynomial with the coefficients [10.0, 20.0, 30.0] and the variables [7.0, 5.0]:
let coefficients: [Double] = [10, 20, 30]
let variables: [Double] = [7, 5]
let result = vDSP.evaluatePolynomial(usingCoefficients: coefficients,
withVariables: variables)
// Prints "[660.0, 380.0]".
// result[0] = (10 * 7²) + (20 * 7¹) + (30 * 7⁰) = 660
// result[1] = (10 * 5²) + (20 * 5¹) + (30 * 5⁰) = 380
print(result)