ppval {pracma}R Documentation

Piecewise Polynomial Structures

Description

Make or evaluate a piecewise polynomial.

Usage

mkpp(x, P)

ppval(pp, xx)

Arguments

x

increasing vector of real numbers.

P

matrix containing the coefficients of polynomials in each row.

pp

a piecewise polynomial structure, generated by mkpp.

xx

numerical vector

Details

pp<-mkpp(x,P) builds a piecewise polynomial from its breaks x and coefficients P. x is a monotonically increasing vector of length L+1, and P is an L-by-k matrix where each row contains the coefficients of the polynomial of order k, from highest to lowest exponent, on the interval [x[i],x[i+1]).

ppval(pp,xx) returns the values of the piecewise polynomial pp at the entries of the vector xx. The first and last polynomial will be extended to the left resp. right of the interval [x[1],x[L+1]).

Value

mkpp will return a piecewise polynomial structure, that is a list with components breaks=x, pieces=P, order=k and dim=1 for scalar-valued functions.

Note

Matlab allows to generate vector-valued piecewise polynomials. This may be included in later versions.

See Also

cubicspline

Examples

##  Example: Linear interpolation of the sine function
xs <- linspace(0, pi, 10)
ys <- sin(xs)
P <- matrix(NA, nrow = 9, ncol = 2)
for (i in 1:9) {
    P[i, ] <- c((ys[i+1]-ys[i])/(xs[i+1]-xs[i]), ys[i])
}
ppsin <- mkpp(xs, P)

## Not run: 
plot(xs, ys); grid()
x100 <- linspace(0, pi, 100)
lines(x100, sin(x100), col="darkgray")
ypp <- ppval(ppsin, x100)
lines(x100, ypp, col="red")

## End(Not run)

[Package pracma version 2.4.4 Index]