##
## add a parabola to itself
##
bspl4 <- create.bspline.basis(nbasis=4)
parab4.5 <- fd(c(3, -1, -1, 3)/3, bspl4)
coef2 <- matrix(c(6, -2, -2, 6)/3, 4)
dimnames(coef2) <- list(NULL, 'reps 1')
stopifnot(
all.equal(coef(parab4.5+parab4.5), coef2)
)
##
## Same example with interior knots at 1/3 and 1/2
##
bspl5.3 <- create.bspline.basis(breaks=c(0, 1/3, 1))
plot(bspl5.3)
x. <- seq(0, 1, .1)
para4.5.3 <- smooth.basis(x., 4*(x.-0.5)^2, fdParobj=bspl5.3)[['fd']]
plot(para4.5.3)
bspl5.2 <- create.bspline.basis(breaks=c(0, 1/2, 1))
plot(bspl5.2)
para4.5.2 <- smooth.basis(x., 4*(x.-0.5)^2, fdParobj=bspl5.2)[['fd']]
plot(para4.5.2)
#str(para4.5.3+para4.5.2)
coef2. <- matrix(0, 9, 1)
dimnames(coef2.) <- list(NULL, 'rep1')
stopifnot(
all.equal(coef(para4.5.3-para4.5.2), coef2.)
)
#str(para4.5.3*para4.5.2)
# interior knots of the sum
# = union(interior knots of the summands);
# ditto for difference and product.
plot(para4.5.3*para4.5.2)
##
## fd+numeric
##
coef1 <- matrix(c(6, 2, 2, 6)/3, 4)
dimnames(coef1) <- list(NULL, 'reps 1')
stopifnot(
all.equal(coef(parab4.5+1), coef1)
)
stopifnot(
all.equal(1+parab4.5, parab4.5+1)
)
##
## fd-numeric
##
coefneg <- matrix(c(-3, 1, 1, -3)/3, 4)
dimnames(coefneg) <- list(NULL, 'reps 1')
stopifnot(
all.equal(coef(-parab4.5), coefneg)
)
plot(parab4.5-1)
plot(1-parab4.5)
Run the code above in your browser using DataLab