<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vDSP/linearInterpolate(elementsOf:using:result:)-4n3lr",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate4vDSPO17linearInterpolate10elementsOf5using6resultyx_q_q0_ztAA0A6BufferRzAaHR_AA0a7MutableI0R0_Sd7ElementRtzSdAJRt_SdAJRt0_r1_lFZ"
  },
  "title" : "linearInterpolate(elementsOf:using:result:)"
}
-->

# linearInterpolate(elementsOf:using:result:)

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

```
static func linearInterpolate<T, U, V>(elementsOf vector: T, using controlVector: U, result: inout V) where T : AccelerateBuffer, U : AccelerateBuffer, V : AccelerateMutableBuffer, T.Element == Double, U.Element == Double, V.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.

`result`

An array that receives the result of the calculation.

## Discussion

Single-precision and double-precision [`linearInterpolate(elementsOf:using:result:)`](/documentation/Accelerate/vDSP/linearInterpolate(elementsOf:using:result:)-4n3lr) functions calculate an array of an arbitrary length that’s constructed from the linearly interpolated values in a source array. Pass [`linearInterpolate(elementsOf:using:result:)`](/documentation/Accelerate/vDSP/linearInterpolate(elementsOf:using:result:)-4n3lr) 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:

```swift
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:)`](/documentation/Accelerate/vDSP/ramp(in:count:)-79aw7) to generate the control vector. The following code creates 1024 interpolated values from 10 source values:

```swift
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`.

![A graph of the linearly interpolated values based on a control vector created with a ramp.](images/com.apple.accelerate/media-3512160@2x.png)

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:

```swift
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.

![A graph of the linearly interpolated values based on a control vector created with a sigmoid function.](images/com.apple.accelerate/media-3512155@2x.png)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)