---
title: "linearInterpolate(elementsOf:using:)"
framework: accelerate
role: symbol
role_heading: Type Method
path: "accelerate/vdsp/linearinterpolate(elementsof:using:)-5i3jc"
---

# linearInterpolate(elementsOf:using:)

Returns the interpolation between the neighboring elements of a double-precision vector.

## Declaration

```swift
static func linearInterpolate<T, U>(elementsOf vector: T, using controlVector: U) -> [Double] where T : AccelerateBuffer, U : AccelerateBuffer, T.Element == Double, U.Element == Double
```

## Parameters

- `vector`: An array that contains the values to interpolate.
- `controlVector`: An array that defines the interpolation: integer parts are indices into vector and fractional parts are interpolation constants.

## Mentioned in

Using linear interpolation to construct new data points

## Discussion

Discussion Single-precision and double-precision linearInterpolate(elementsOf:using:) functions return an array of an arbitrary length that’s constructed from the linearly interpolated values in a source array. Pass linearInterpolate(elementsOf:using:) a control vector that defines the interpolation: the integer part of each element in the control vector is the zero-based index of the first element of a pair of adjacent values in the source array, and the fractional part defines the linear interpolation between the values at those indices. For example, the following code generates a five-element vector by interpolating three values: let result = vDSP.linearInterpolate(elementsOf: [100, 200, 300],                                     using: [0, 0.5, 1, 1.5, 2]) On return, result contains [100.0, 150.0, 200.0, 250.0, 300.0]. To compute longer interpolation results, use ramp(in:count:) to generate the control vector. The following code creates 1024 interpolated values from 10 source values: let values: [Float] = [50, 90, 55, 10, 40, 85, 65, 15, 30, 80] let controlVector: [Float] = vDSP.ramp(in: 0 ... Float(values.count) - 1,                                        count: 1024)

let result = vDSP.linearInterpolate(elementsOf: values,                                     using: controlVector) The following figure visualizes the elements in result.

By changing the technique used to form the fractional parts of the control vector, you change the interpolation between the values in the source vector. The following code uses a sigmoid function—that is, a function that has an “S” shaped curve—to populate the control vector: let values: [Float] = [50, 90, 55, 10, 40, 85, 65, 15, 30, 80]

let denominator = 1024 / Float(values.count - 1) let tau = Float.pi * 2 let controlVector: [Float] = (0 ..< 1024).map {     let x = modf(Float($0) / denominator)          return x.0 + (tanh((x.1 - 0.5) * tau) * 0.5) + 0.5 }

let result = vDSP.linearInterpolate(elementsOf: values,                                     using: controlVector) The following figure visualizes the elements in result using hyperbolic tangent for the sigmoid function.

## See Also

### Single-Vector Linear Interpolation

- [Using linear interpolation to construct new data points](accelerate/using-linear-interpolation-to-construct-new-data-points.md)
- [linearInterpolate(elementsOf:using:)](accelerate/vdsp/linearinterpolate(elementsof:using:)-49r3c.md)
- [linearInterpolate(elementsOf:using:result:)](accelerate/vdsp/linearinterpolate(elementsof:using:result:)-4n3lr.md)
- [linearInterpolate(elementsOf:using:result:)](accelerate/vdsp/linearinterpolate(elementsof:using:result:)-9y61c.md)
