Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# fntlr

Taylor coefficients or polynomial

## Syntax

taylor = fntlr(f,dorder,x)
p = fntlr(f,dorder,x,interv)

## Description

taylor = fntlr(f,dorder,x) returns the unnormalized Taylor coefficients, up to the given order dorder and at the given x, of the function described in f .

For a univariate function and a scalar x, this is the vector

If, more generally, the function in f is d-valued with d>1 or even prod(d)>1 and/or is m-variate for some m>1, then dorder is expected to be an m-vector of positive integers, x is expected to be a matrix with m rows, and, in that case, the output is of size [prod(d)*prod(dorder),size(x,2)], with its j-th column containing

for i1=1:dorder(1), ..., im=1:dorder(m). Here, Dif is the partial derivative of f with respect to its ith argument.

p = fntlr(f,dorder,x,interv) returns instead a ppform of the Taylor polynomial at x of order dorder for the function described by f. The basic interval for this ppform is as specified by interv. In this case and assuming that the function described by f is m-variate, x is expected to be of size [m,1], and interv is either of size [m,2] or else a cell array of length m containing m vectors of size [1,2].

## Examples

If f contains a univariate function and x is a scalar or a 1-row matrix, then fntlr(f,3,x) produces the same output as the statements

```df = fnder(f); [fnval(f,x); fnval(df,x); fnval(fnder(df),x)];
```

As a more complicated example, look at the Taylor vectors of order 3 at 21 equally spaced points for the rational spline whose graph is the unit circle:

```ci = rsmak('circle'); in = fnbrk(ci,'interv');
t = linspace(in(1),in(2),21); t(end)=[];
v = fntlr(ci,3,t);
```

We plot ci along with the points v(1:2,:), to verify that these are, indeed, points on the unit circle.

```fnplt(ci), hold on, plot(v(1,:),v(2,:),'o')
```

Next, to verify that v(3:4,j) is a vector tangent to the circle at the point v(1:2,j), we use the MATLAB® quiver command to add the corresponding arrows to our plot:

```quiver(v(1,:),v(2,:),v(3,:),v(4,:))
```

Finally, what about v(5:6,:)? These are second derivatives, and we add the corresponding arrows by the following quiver command, thus finishing First and Second Derivative of a Rational Spline Giving a Circle.

```quiver(v(1,:),v(2,:),v(5,:),v(6,:)), axis equal, hold off
```

First and Second Derivative of a Rational Spline Giving a Circle

Now, our curve being a circle, you might have expected the 2nd derivative arrows to point straight to the center of that circle, and that would have been indeed the case if the function in ci had been using arclength as its independent variable. Since the parameter used is not arclength, we use the formula, given in Example: B-form Spline Approximation to a Circle, to compute the curvature of the curve given by ci at these selected points. For ease of comparison, we switch over to the variables used there and then simply use the commands from there.

```dspt = v(3:4,:); ddspt = v(5:6,:);
kappa = abs(dspt(1,:).*ddspt(2,:)-dspt(2,:).*ddspt(1,:))./...
(sum(dspt.^2)).^(3/2);
max(abs(kappa-1))
ans = 2.2204e-016
```

The numerical answer is reassuring: at all the points tested, the curvature is 1 to within roundoff.

The Function 1/(1+x^2+y^2) and Its Taylor Polynomial of Order[3,3] at the Origin

As a final example, we start with a bivariate version of the Runge function, obtaining, for variety, a ppform for its denominator, 1 + x2 + y2, by bicubic spline interpolation:

```w = csapi({-1:1,-1:1},[3 2 3;2 1 2;3 2 3]);
```

Next, we make up the coefficient array for the numerator, 1, using exactly the same size, and put the two together into a rational spline:

```wcoefs = fnbrk(w,'coef');
scoefs = zeros(size(wcoefs)); scoefs(end)=1;
runge2 = rpmak(fnbrk(w,'breaks'),[scoefs;wcoefs]);
```

Then we enlarge the basic interval for this rational spline, plot it and plot, on top of it, its Taylor polynomial at (0,0) of order [3,3].

```fnplt(fnbrk(runge2,{[-2 2],[-2 2]}));  shading interp, hold on
fnplt(fntlr(runge2,[3 3],[0;0],[-.7 .7; -.7 .7]))
axis off, hold off
```

Since we shaded the function but not the Taylor polynomial, we can easily distinguish the two in the previous figure. We can also see that, in contrast to the function, the Taylor polynomial fails to be rotationally symmetric. This is due to the fact that it is a polynomial of order [3,3] rather than a polynomial of total order 3.

To obtain the Taylor polynomial of order 3, we get the Taylor polynomial of order [3,3], but with (0,0) the left point of its basic interval, set all its coefficients of total order bigger than 3 equal to zero, and then reconstruct the polynomial, and plot it, choosing a different view in order to show off the Taylor polynomial better. Here are the commands and the resulting figure.

```taylor = fntlr(runge2,[3 3],[0;0],[0 1;0 1]);
tcoef = fnbrk(taylor,'coe'); tcoef([1 2 4]) = 0;
taylor2 = fnbrk(ppmak(fnbrk(taylor,'br'),tcoef),{[-1 1],[-1
1]});
fnplt(fnbrk(runge2,{[-2 2],[-2 2]}));  shading interp, hold on
fnplt(taylor2), view(-28,-26), axis off, hold off
```

The Function 1/(1+x^2+y^2) and Its Taylor Polynomial of Order 3 at the Origin