# NOT RUN {
##
## sin^2
##
basis3 <- create.fourier.basis(nbasis=3)
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
# }
# NOT RUN {
all.equal(fdsin2, fdsinsin)
# }
# NOT RUN {
# }
# NOT RUN {
<!-- % ## -->
# }
# NOT RUN {
<!-- % ## sqrt(sin2) -->
# }
# NOT RUN {
<!-- % ## -->
# }
# NOT RUN {
<!-- % plot(fdsin2) -->
# }
# NOT RUN {
<!-- % fdsin. <- sqrt(fdsin2) -->
# }
# NOT RUN {
<!-- % plot(fdsin, main='fdsin and sqrt(fdsin^2)') -->
# }
# NOT RUN {
<!-- % lines(fdsin., col='red') -->
# }
# NOT RUN {
<!-- % # fdsin is positive and negative -->
# }
# NOT RUN {
<!-- % # fdsin. = sqrt(fdsin^2) -->
# }
# NOT RUN {
<!-- % # has trouble, because it wants to be smooth -->
# }
# NOT RUN {
<!-- % # but theoretically has a discontinuous first derivative at 0.5 -->
# }
# NOT RUN {
# }
# NOT RUN {
<!-- % fdsin.5.2 <- fdsin.^2 -->
# }
# NOT RUN {
<!-- % resin <- fdsin2-fdsin.5.2 -->
# }
# NOT RUN {
<!-- % plot(resin) -->
# }
# NOT RUN {
<!-- % \dontshow{stopifnot(} -->
# }
# NOT RUN {
<!-- % max(abs(resin$coefs))<0.01 -->
# }
# NOT RUN {
<!-- % \dontshow{)} -->
# }
# NOT RUN {
# }
# NOT RUN {
<!-- % ## -->
# }
# NOT RUN {
<!-- % ## x^2, x = straight line f(x)=x -->
# }
# NOT RUN {
<!-- % ## -->
# }
# NOT RUN {
<!-- % bspl1 <- create.bspline.basis(norder=2) -->
# }
# NOT RUN {
<!-- % x <- fd(0:1, bspl1) -->
# }
# NOT RUN {
<!-- % plot(x) -->
# }
# NOT RUN {
# }
# NOT RUN {
<!-- % x2 <- x^2 -->
# }
# NOT RUN {
<!-- % plot(x2) -->
# }
# NOT RUN {
# }
# NOT RUN {
<!-- % er.x <- x-sqrt(x2) -->
# }
# NOT RUN {
<!-- % er.x$coefs -->
# }
# NOT RUN {
<!-- % max(er.x$coefs) -->
# }
# NOT RUN {
<!-- % \dontshow{stopifnot(} -->
# }
# NOT RUN {
<!-- % max(abs(er.x$coefs))<10*.Machine$double.eps -->
# }
# NOT RUN {
<!-- % \dontshow{)} -->
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab