Learn R Programming

cSFM (version 1.1)

legendre.polynomials: Orthogonal Legendre Polynomials Basis System

Description

Generate Legendre polynomials as an orthogonal basis system in the interval [0, 1]. The set of polynomial functions are used to be the eigenfunctions to generate the covariance matrix of a latent process.

Usage

legendre.polynomials(t, degree, normalized = TRUE)

Arguments

t
the set of values to be evaluated, taking values from [0, 1]
degree
the polynomial degree of the function, taking values as 0 (constant), 1 (linear), 2 (quadratic) and 3 (cubic)
normalized
logical value; If TRUE (default) then the values are normalized such that the $L2$ norm of the function values is 1

Value

  • A vector which are the evaluations of the Legendre polynomial function at t.

Details

Legendre polynomials can take any integers as degree, however, it is sufficent for most applications up to degree = 3. It is also messy to obtain the exploit expression for a degree greater than 3. The logical value normalized take TRUE as the default, which means the generated eigenfunction basis matrix will be an orthogonal matrix.

See Also

DFT.basis

Examples

Run this code
# time points 
t <- seq(from = 0, to = 1, length = 100)
# basis matrix evaluated at the time points t
# an intercept column is included
Phi <- cbind(legendre.polynomials(t, degree = 0), legendre.polynomials(t, degree = 1),
             legendre.polynomials(t, degree = 2), legendre.polynomials(t, degree = 3))
# check the orthogonality
crossprod(Phi) # is equal to I_4 up to rounding errors
# plot the basis system excluding the constant column
matplot(t, Phi[,2:4], type = "l", lwd = 2, lty = 1:3, 
        ylab = "basis function", main = "Legendre Polynomials (normalized)")
legend("top", c("linear", "quadratic", "cubic"), col = 1:3, lwd = 2, lty = 1:3)

Run the code above in your browser using DataLab