Skip to content

Latest commit

 

History

History
67 lines (45 loc) · 1.39 KB

interp.md

File metadata and controls

67 lines (45 loc) · 1.39 KB

interp

Interpolate values at query points using piecewise linear segments.

API

Numeric.math.interp(query, points, values, lower, right, period)

Performs piecewise linear interpolation between known points.

  • Parameters:
    • query: Positions where values are requested
    • points: Sorted sample positions of the known values
    • values: Sample values paired with the positions
    • lower: Value returned for queries below the range
    • right: Value returned for queries above the range
    • period: Optional period for cyclic interpolation
  • Returns: Interpolated values at the query positions
  • NumPy: Equivalent to np.interp.

Examples

Interpolate one query point

import Numeric from '@neabyte/numerix'

const value = Numeric.math.interp(2.5, [0, 1, 2, 3], [0, 10, 20, 30])

console.log(value)
// 25

Interpolate several query points

import Numeric from '@neabyte/numerix'

const values = Numeric.math.interp([0.5, 1.5], [0, 1, 2], [0, 10, 20])

console.log(values)
// [5,15]

Query on a sample point returns the sample

import Numeric from '@neabyte/numerix'

const value = Numeric.math.interp(1, [0, 1, 2], [0, 10, 20])

console.log(value)
// 10

Bound values apply outside the sample range

import Numeric from '@neabyte/numerix'

const value = Numeric.math.interp(-1, [0, 1, 2], [0, 10, 20], -99, 99)

console.log(value)
// -99