Learn R Programming

comphy (version 1.0.5)

linpol: 1D linear interpolation

Description

Classic linear interpolation between two tabulated (known) points of a one-variable function.

Usage

linpol(x, f, x0)

Value

A vector of real numbers. These are the actual interpolated values (calculated using linear interpolation), corresponding to all values of the grid x0.

Arguments

x

A vector of real numbers. Grid points corresponding to the tabulated (known) values of the function.

f

A vector of real numbers. Tabulated (known) values of the function, corresponding to the grid x.

x0

A vector of real numbers. These are the grid points chosen for the interpolation. All points of this grid need to be within the tabulated grid.

Examples

Run this code
# Tabulated values: f(x) = 2*x^2-1
x <- c(0,1,3,7)
f <- 2*x^2-1

# Grid for interpolation
x0 <- seq(0,7,length=501)

# Interpolated points
f <- linpol(x,f,x0)
print(f)

Run the code above in your browser using DataLab