# taylor: Taylor Series Approximation In pracma: Practical Numerical Math Functions

## Description

Local polynomial approximation through Taylor series.

## Usage

 `1` ```taylor(f, x0, n = 4, ...) ```

## Arguments

 `f` differentiable function. `x0` point where the series expansion will take place. `n` Taylor series order to be used; should be `n <= 8`. `...` more variables to be passed to function `f`.

## Details

Calculates the first four coefficients of the Taylor series through numerical differentiation and uses some polynomial ‘yoga’.

## Value

Vector of length `n+1` representing a polynomial of degree `n`.

`fderiv`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16``` ```taylor(sin, 0, 4) #=> -0.1666666 0.0000000 1.0000000 0.0000000 taylor(exp, 1, 4) #=> 0.04166657 0.16666673 0.50000000 1.00000000 1.00000000 f <- function(x) log(1+x) p <- taylor(f, 0, 4) p # log(1+x) = 0 + x - 1/2 x^2 + 1/3 x^3 - 1/4 x^4 +- ... # [1] -0.250004 0.333334 -0.500000 1.000000 0.000000 ## Not run: x <- seq(-1.0, 1.0, length.out=100) yf <- f(x) yp <- polyval(p, x) plot(x, yf, type = "l", col = "gray", lwd = 3) lines(x, yp, col = "red") grid() ## End(Not run) ```

### Example output

```[1] -0.1666666  0.0000000  1.0000000  0.0000000
[1]  1.132622e-01 -1.965896e-06  6.795734e-01  9.060919e-01  1.019356e+00
[1] -0.2500044  0.3333339 -0.5000000  1.0000000  0.0000000
```

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