ppval | R Documentation |
Make or evaluate a piecewise polynomial.
mkpp(x, P)
ppval(pp, xx)
x |
increasing vector of real numbers. |
P |
matrix containing the coefficients of polynomials in each row. |
pp |
a piecewise polynomial structure, generated by |
xx |
numerical vector |
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])
.
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.
Matlab allows to generate vector-valued piecewise polynomials. This may be included in later versions.
cubicspline
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.