fornberg: Fornberg's Finite Difference Approximation

View source: R/fornberg.R

fornbergR Documentation

Fornberg's Finite Difference Approximation

Description

Finite difference approximation using Fornberg's method for the derivatives of order 1 to k based on irregulat grid values.

Usage

fornberg(x, y, xs, k = 1)

Arguments

x

grid points on the x-axis, must be distinct.

y

discrete values of the function at the grid points.

xs

point at which to approximate (not vectorized).

k

order of derivative, k<=length(x)-1 required.

Details

Compute coefficients for finite difference approximation for the derivative of order k at xs based on grid values at points in x. For k=0 this will evaluate the interpolating polynomial itself, but call it with k=1.

Value

Returns a matrix of size (length(xs)), where the (k+1)-th column gives the value of the k-th derivative. Especially the first column returns the polynomial interpolation of the function.

Note

Fornberg's method is considered to be numerically more stable than applying Vandermonde's matrix.

References

LeVeque, R. J. (2007). Finite Difference Methods for Ordinary and Partial Differential Equations. Society for Industrial and Applied Mathematics (SIAM), Philadelphia.

See Also

neville, newtonInterp

Examples

x <- 2 * pi * c(0.0, 0.07, 0.13, 0.2, 0.28, 0.34, 0.47, 0.5, 0.71, 0.95, 1.0)
y <- sin(0.9*x)
xs <- linspace(0, 2*pi, 51)
fornb <- fornberg(x, y, xs, 10)
## Not run: 
matplot(xs, fornb, type="l")
grid()
## End(Not run)

pracma documentation built on Nov. 10, 2023, 1:14 a.m.