Description Usage Arguments Details Value See Also Examples
View source: R/exponentiate.fd.R
Exponentiate a functional data object where feasible.
1 2 3 4 5 6 7 |
e1 |
object of class 'fd'. |
e2 |
a numeric vector of length 1. |
basisobj |
reference basis |
tolint |
if abs(e2-round(e2))<tolint, we assume e2 is an integer. This simplifies the algorithm. |
tolfd |
the maximum error allowed in the difference between the direct
computation |
maxbasis |
The maximum number of basis functions in growing
|
npoints |
The number of points at which to compute |
If e1 has a B-spline basis, this uses the B-spline algorithm.
Otherwise it throws an error unless it finds one of the following special cases:
e2 = 0
Return an fd
object with a constant basis that is
everywhere 1
e2 is a positive integer to within tolint Multiply e1 by itself e2 times
e2 is positive and e1 has a Fourier basis e120 <- e1^floor(e2)
outBasis <- e120$basis
rng <- outBasis$rangeval
Time <- seq(rng[1], rng[2], npoints)
e1.2 <- predict(e1, Time)^e2
fd1.2 <- Data2fd(Time, e1.2, outBasis)
d1.2 <- (e1.2 - predict(fd1.2, Time))
if(all(abs(d1.2)<tolfd))return(fd1.2)
Else if(outBasis$nbasis<maxbasis) increase the size of outBasis and try again.
Else write a warining with the max(abs(d1.2)) and return fd1.2.
A function data object approximating the desired power.
arithmetic.fd
basisfd
,
basisfd.product
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | ##
## 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
all.equal(fdsin2, fdsinsin)
##
## sqrt(sin2)
##
plot(fdsin2)
fdsin. <- sqrt(fdsin2)
plot(fdsin, main='fdsin and sqrt(fdsin^2)')
lines(fdsin., col='red')
# fdsin is positive and negative
# fdsin. = sqrt(fdsin^2)
# has trouble, because it wants to be smooth
# but theoretically has a discontinuous first derivative at 0.5
fdsin.5.2 <- fdsin.^2
resin <- fdsin2-fdsin.5.2
plot(resin)
max(abs(resin$coefs))<0.01
##
## x^2, x = straight line f(x)=x
##
bspl1 <- create.bspline.basis(norder=2)
x <- fd(0:1, bspl1)
plot(x)
x2 <- x^2
plot(x2)
er.x <- x-sqrt(x2)
er.x$coefs
max(er.x$coefs)
max(abs(er.x$coefs))<10*.Machine$double.eps
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.