Learn R Programming

pracma (version 1.8.6)

polyApprox: Polynomial Approximation

Description

Generate a polynomial approximation.

Usage

polyApprox(f, a, b, n, ...)

Arguments

f
function to be approximated.
a, b
end points of the interval.
n
degree of the polynomial.
...
further variables for function f.

Value

  • List with three components: the approximating polynomial, a function evaluating this polynomial, and the estimated precision over the given interval.

Details

Uses the Chebyshev coefficients to derive polynomial coefficients.

References

Carothers, N. L. (1998). A Short Course on Approximation Theory. Bowling Green State University, URL: http://personal.bgsu.edu/~carother/Approx.html.

See Also

chebApprox, polyfit

Examples

Run this code
##  Example
#   Polynomial approximation for sin
polyApprox(sin, -pi, pi, 9)
# $p
#  [1]  0.06549943  0.00000000 -0.58518036  0.00000000  2.54520983
#  [7]  0.00000000 -5.16709776  0.00000000  3.14158037  0.00000000
# 
# $f
# function (x) 
# polyval(r, x)
# <environment: 0x1f978e8>
# 
# $estim.prec
# [1] 1.151207e-05

f <- polyApprox(sin, -pi, pi, 9)$f
x <- seq(-pi, pi, length.out = 100)
y <- sin(x) - f(x)
plot(x, y, type = "l", col = "blue")
grid()

Run the code above in your browser using DataLab