# barylag: Barycentric Lagrange Interpolation In pracma: Practical Numerical Math Functions

## Description

Barycentric Lagrange interpolation in one dimension.

## Usage

 `1` ```barylag(xi, yi, x) ```

## Arguments

 `xi, yi` x- and y-coordinates of supporting nodes. `x` x-coordinates of interpolation points.

## Details

`barylag` interpolates the given data using the barycentric Lagrange interpolation formula (vectorized to remove all loops).

## Value

Values of interpolated data at points `x`.

## Note

Barycentric interpolation is preferred because of its numerical stability.

## References

Berrut, J.-P., and L. Nick Trefethen (2004). “Barycentric Lagrange Interpolation”. SIAM Review, Vol. 46(3), pp.501–517.

Lagrange or Newton interpolation.

## Examples

 ``` 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``` ```## Generates an example with plot. # Input: # fun --- function that shall be 'approximated' # a, b --- interval [a, b] to be used for the example # n --- number of supporting nodes # m --- number of interpolation points # Output # plot of function, interpolation, and nodes # return value is NULL (invisible) ## Not run: barycentricExample <- function(fun, a, b, n, m) { xi <- seq(a, b, len=n) yi <- fun(xi) x <- seq(a, b, len=m) y <- barylag(xi, yi, x) plot(xi, yi, col="red", xlab="x", ylab="y", main="Example of barycentric interpolation") lines(x, fun(x), col="yellow", lwd=2) lines(x, y, col="darkred") grid() } barycentricExample(sin, -pi, pi, 11, 101) # good interpolation barycentricExample(runge, -1, 1, 21, 101) # bad interpolation ## End(Not run) ```

### Example output

```
```

pracma documentation built on Dec. 11, 2021, 9:57 a.m.