Torsten

Version 0.89.0

A pharmacokinetics/pharmacodynamics library for Stan

Piecewise linear interpolation

real linear_interpolation(real xout, real[] x, real[] y)
real[] linear_interpolation(real[] xout, real[] x, real[] y)

Torsten also provides function linear_interpolation for piecewise linear interpolation over a set of x, y pairs. It returns the values of a piecewise linear function at specified values xout of the first function argument. The function is specified in terms of a set of x, y pairs. Specifically, linear_interpolation implements the following function

\begin{align*} y_{\text{out}} = \left\{\begin{array}{ll} y_1, & x_{\text{out}} < x_1 \\\
y_i + \frac{y_{i+1} - y_i}{x_{i+1} - x_i} \left(x_{\text{out}} - x_i\right), & x_{\text{out}} \in [x_i, x_{i+1}) \\\
y_n, & x_{\text{out}} \ge x_n \end{array}\right. \end{align*}

  • The x values must be in increasing order, i.e. \(x_i < x_{i+1}\).
  • All three arguments may be data or parameters.
Last updated on 30 Jun 2021
Published on 25 Jun 2021
 Edit on GitHub