Learn R Programming

basefun (version 1.1-4)

Legendre_basis: Legendre Basis Functions

Description

Basis functions defining a Legendre polynomial

Usage

Legendre_basis(var, order = 2, ui = c("none", "increasing", "decreasing", 
                                      "cyclic", "positive", "negative"), ...)

Arguments

var

a numeric_var object

order

the order of the polynomial, one defines a linear function

ui

a character describing possible constraints

...

additional arguments passed to legendre.polynomials

Details

Legendre_basis returns a function for the evaluation of the basis functions with corresponding model.matrix and predict methods.

References

Rida T. Farouki (2012), The Bernstein Polynomial Basis: A Centennial Retrospective, Computer Aided Geometric Design, 29(6), 379--419. http://dx.doi.org/10.1016/j.cagd.2012.03.001

Examples

Run this code

  ### set-up basis
  lb <- Legendre_basis(numeric_var("x", support = c(0, pi)), 
                       order = 3)

  ### generate data + coefficients
  x <- as.data.frame(mkgrid(lb, n = 100))
  cf <- c(1, 2, 2.5, 1.75)

  ### evaluate basis (in two equivalent ways)
  lb(x[1:10,,drop = FALSE])
  model.matrix(lb, data = x[1:10, ,drop = FALSE])

  ### evaluate and plot Legendre polynomial defined by
  ### basis and coefficients
  plot(x$x, predict(lb, newdata = x, coef = cf), type = "l")

Run the code above in your browser using DataLab