##
## sin^2
##
basis3 <- create.fourier.basis(nbasis=3)
oldpar <- par(no.readonly=TRUE)
plot(basis3)
# max = sqrt(2), so
# integral of the square of each basis function (from 0 to 1) is 1
integrate(function(x)sin(2*pi*x)^2, 0, 1) # = 0.5
# sin(theta)
fdsin <- fd(c(0,sqrt(0.5),0), basis3)
plot(fdsin)
fdsin2 <- fdsin^2
# check
fdsinsin <- fdsin*fdsin
# sin^2(pi*time) = 0.5*(1-cos(2*pi*theta) basic trig identity
plot(fdsinsin) # good
stopifnot(
all.equal(fdsin2, fdsinsin)
)
par(oldpar)
Run the code above in your browser using DataLab