Interpolator Module

The interpolator module provides functionality for linear interpolation between a set of values over a time interval.

Functions

interpolate(t, yi, yf, ti, tf, ylist, continuous=True)[source]

Performs linear interpolation between points.

Parameters:
  • t – time at which to interpolate

  • yi – initial value at t=ti

  • yf – final value at t=tf

  • ti – initial time

  • tf – final time

  • ylist – list of values to interpolate between

  • continuous – if True, add yi and yf to the beginning and end of ylist

Returns:

The interpolated value at time t

make_interpolator(yi, yf, ti, tf, ylist, continuous=True)[source]

Obsolete: refactored as class Interpolator.

Builds a linear interpolation function y(t) from a list of values ylist at times [ti, tf] and initial and final values yi, yf.

Parameters:
  • yi – initial value of y

  • yf – final value of y

  • ti – initial time

  • tf – final time

  • ylist (list) – list of values of y at times [ti, tf]

  • continuous (bool) – whether the interpolator is continuous at ti and tf

Classes

class Interpolator(yi, yf, ti, tf, ylist, continuous=True)[source]

Builds a linear interpolation function y(t) from a list of values ylist at times [ti, tf] and initial and final values yi, yf.

__init__(yi, yf, ti, tf, ylist, continuous=True)[source]

Initializes the interpolator function y(t) from a list of values ylist at times [ti, tf] and initial and final values yi, yf.

Parameters:
  • yi – initial value of y

  • yf – final value of y

  • ti – initial time

  • tf – final time

  • ylist (list) – list of values of y at times [ti, tf]

  • continuous (bool) – whether the interpolator is continuous at ti and tf

Example Usage

Here’s an example of how to use the interpolator:

from langesim_optim.interpolator import Interpolator, make_interpolator

# Create an interpolator object
interp = Interpolator(
    yi=0.0,        # Initial value
    yf=1.0,        # Final value
    ti=0.0,        # Initial time
    tf=1.0,        # Final time
    ylist=[0.2, 0.5, 0.8],  # Values at intermediate points
    continuous=True  # Make the interpolation continuous
)

# Get interpolated value at a specific time
t = 0.5
y = interp(t)

# Alternatively, use the make_interpolator function
interp_func = make_interpolator(
    yi=0.0,
    yf=1.0,
    ti=0.0,
    tf=1.0,
    ylist=[0.2, 0.5, 0.8]
)
y = interp_func(t)