cardinalBasis_natSpline: Cardinal Basis for natural cubic spline interpolation

View source: R/splines1d.R

cardinalBasis_natSplineR Documentation

Cardinal Basis for natural cubic spline interpolation

Description

Cardinal Basis for natural cubic spline interpolation.

Usage

cardinalBasis_natSpline(x, xout, deriv = 0)

Arguments

x

Numeric vector of design points.

xout

Numeric vector of new points.

deriv

Integer. Order of derivation. Can be 0, 1 or 2.

Details

This is a simple and raw interface to splinterp Fortran subroutine.

Value

A list with several elements

x

Numeric vector of abscissas at which the basis is evaluated. This is a copy of xout.

CB

Matrix of the Cardinal Basis function values.

deriv

Order of derivation as given on input.

method

Character description of the method involved in the CB determination.

Author(s)

Yves Deville

Examples

set.seed(123)
n <- 16; nout <- 360
x <- sort(runif(n))

## let 'xout' contain n + nout points including nodes 
xout <- sort(c(x, seq(from =  x[1] + 1e-8, to = x[n] - 1e-8, length.out = nout)))
res  <- cardinalBasis_natSpline(x, xout = xout)

matplot(res$x, res$CB, type = "n", main = "Cardinal Basis")
abline(v = x, h = 1.0, col = "gray")
points(x = x, y = rep(0, n), pch = 21, col = "black", lwd = 2, bg = "white")
matlines(res$x, res$CB, type = "l")

## compare with 'splines'
require(splines)
y <- sin(2* pi * x)
sp <- interpSpline(x, y)
test <- rep(NA, 3)
der <- 0:2
names(test) <- nms <- paste("deriv. ", der, sep = "")
for (i in seq(along = der)) {
   resDer <- cardinalBasis_natSpline(x, xout = xout, deriv = der[i])
   test[nms[i]] = max(abs(predict(sp, xout, deriv = der[i])$y - resDer$CB %*% y))
}
test
## Lebesgue's function
plot(x = xout, y = apply(res$CB, 1, function(x) sum(abs(x))), type = "l",
     lwd = 2, col = "orangered", main = "Lebesgue\'s function", log = "y",
     xlab = "x", ylab = "L(x)")
points(x = x, y = rep(1, n), pch = 21, col = "black", lwd = 2, bg = "white")

IRSN/smint documentation built on Dec. 9, 2023, 9:53 p.m.