# “Taylor” approximation of a function, based on 2 rather than 1 base points?

Normally, when we want to approximate a function $f(x)$ close to $x=a$, we do a Taylor approximation around $a$:

$$f(x)\approx f(a)+f'(a)(x-a)+...$$

However, what if we want to approximate a function $f(x)$ on the interval $[a,b]$, by an approximating function $g(x)$ where we require the following:

1. Contrary to Taylor approximation, where we only necessarily have that $g(a)=f(a)$ for some $a$. We now require two endpoints to coincide. That is, we need $g(a)=f(a)$ and $g(b)=f(b)$

2. Ideally: g(x) should be simple, easily integrable, analytically tractable, and (just like Taylor approximation) allow for arbitrary degrees of precision. Preferably polynomial.

3. We only care about the approximation on the interval $[a,b]$. That is, we need $g(x)\approx f(x)$ on $x\in[a,b]$ only.

4. We care whether the integrals of $f(x)$ and $g(x)$ on $[a,b]$ are approximately equal for arbitrary functions $f(x)$.

5. Moreover, the approximation should ideally be the "best" approximation in its class $\mathcal C$. By $\mathcal C$ I mean for example, the class of polynomial functions of degree $n$. If we want more precision, we can then increase $n$. I am open to different definitions of "best", but I am thinking of something like "the integral of $g(x)$ on $[a,b]$ should be the closest to that of $f(x)$ on that interval out of all possible g(x) in class $\mathcal C$".

Is there a canonical technique, similar to Taylor approximation, that satisfies these requirements? Or satisfy some of them?

The most simple approximation I can come up with is simply, $g(x)=A+Bx$ with $A,B$ such that $g(a)=f(a), g(b)=f(b)$. This determines a unique function. However, when we add a quadratic term, there are now an infinite amount of functions satisfying the boundary conditions, so which one of them is the "best"?

• Randomly spitballing here: Take the taylor expansion around x=a and around x=b and average the two? – ASKASK Jan 8 '18 at 8:54
• That would be a special case of Langrange-Hermite interpolation, with just two points, but many derivatives. I've read something about that, but... that must have been in the eighties. – Professor Vector Jan 8 '18 at 8:59
• Believe it or not, but the NASA investigated that in 1966. – Professor Vector Jan 8 '18 at 9:17
• Why not Taylor in the point (b-a)? In this case the error will become higher and higher as far you go close to the sup and min if the interval but its probably the best approxumation? This looks like an interpolation problem uh? – Osvaldo Paniccia Jan 8 '18 at 14:02
• Seems to me that the natural definition of "bestness" would be a least-squares criterion: you want $\int_a^b \left(f(x)-g(x) \right)^2 dx$ to be minimized. No? – mweiss Jan 8 '18 at 14:51

It all depends on what you mean by "best." A reasonably nice choice of "best" is to define a metric based on a norm induced by an inner product of the form

$$\langle f, g \rangle_w = \int_a^b f(x) g(x) w(x) \, dx$$

where $w$ is a so-called weight function, then define "best" to mean closest in this metric. In other words, given $f$ you want to minimize

$$d(f, g)^2 = \| f - g \|^2 = \int_a^b (f(x) - g(x))^2 \, w(x) \, dx.$$

where $g$ lies in some class of functions.

If the class of functions you care about is polynomials, this can be solved nicely by computing the orthogonal polynomials $p_n(x)$ with respect to the weight $w$ using Gram-Schmidt and then using these to compute the projection of any function onto the subspace of polynomials of degree at most $n$; if we normalize $p_n(x)$ (which has degree $n$) to have length $1$ then this projection is given by

$$f \mapsto \sum_{i=0}^n \langle f, p_i \rangle p_i.$$

The weight $w(x)$ lets you adjust how much you care about the approximation being close at each point in the interval $[a, b]$: if you care about each point equally then you can just pick $w(x) = 1$, in which case the orthogonal polynomials you get will be the Legendre polynomials up to scaling and a mild change of variables. The resulting approximation scheme is sometimes called Legendre approximation; see for example this MATLAB lab.

Note also that if $w(x) = 1$ then $\langle f(x), 1 \rangle$ is just the integral of $f$, so as soon as $n \ge 0$ this approximation automatically has the property that it has the same integral over $[a, b]$ as $f$.

There is no guarantee that this approximation is exact at the endpoints, but you can weight how much you care about the endpoints by modifying the weight function to increase the weight of the endpoints, although this may make it more difficult to calculate the resulting orthogonal polynomials. At the extremes you can even add a delta function at the endpoints, which amounts to considering a modified inner product of the form

$$\langle f, g \rangle = \int_a^b f(x) g(x) \, dx + C (f(a) g(a) + f(b) g(b))$$

where the parameter $C$ controls how much you care about the endpoints as opposed to the rest of the interval. Beware that caring more about the endpoints comes at the cost of making the approximation on the rest of the interval worse so there's a tradeoff here.

I want to point out that this procedure is really not analogous to Taylor expansion; among other things, you can do it even for a function which is not differentiable, as it involves computing integrals and not derivatives. The sense in which the Taylor series gives "best" approximations is as one gets arbitrarily close to a point, not in any particular neighborhood of a point.

• I was going to say "Legendre", and leave it at that, but this answer is so much better, and gets so much to the point of the question, and the tradeoffs, etc. ... I'm in awe. :) – John Hughes Jan 8 '18 at 21:28

Here is another approach. One way to think of approximating a function $f(x)$ with a Taylor polynomial of degree $n$ (at $x=a$) is that it is the unique $n$th degree polynomial $p_n(x)$ satisfying $$p_n(a) = f(a)$$ $$p'_n(a) = f'(a)$$ $$p''_n(a) = f''(a)$$ $$\vdots$$ $$p^{(n)}_n(a) = f^{(n)}(a)$$

Think of those requirements as a specification of what "best" means in the context of a normal Taylor polynomial. What are the equivalent specifications when you have two points?

Well, suppose we have two points $a$ and $b$, and we want to require that some polynomial $P(x)$ satisfies all of the following:

$$P(a) = f(a)$$ $$P'(a) = f'(a)$$ $$P''(a) = f''(a)$$ $$\vdots$$ $$P^{(n)}(a) = f^{(n)}(a)$$ $$P(b) = f(b)$$ $$P'(b) = f'(b)$$ $$P''(b) = f''(b)$$ $$\vdots$$ $$P^{(n)}(b) = f^{(n)}(b)$$

That's a set of $2n+2$ requirements, and in general we'd need a polynomial of $2n+1$ in order to satisfy all of them. So let's propose a working definition of a two-point Taylor polynomial:

Definition: The two-point Taylor polynomial of order $n$ is unique polynomial of minimal degree satisfying the $2n+2$ requirements above.

The two-point Taylor polynomial of order $0$ is just the linear interpolation $L_{a,b}(x)$ between the two points $(a,f(a))$ and $(b,f(b))$. This polynomial passes through the correct points, but does not match any of the derivatives. Explicitly, $$L_{a,b}(x)=f(a) + \frac{f(b)-f(a)}{b-a}(x-a)$$

If you want to not only match the values of $f(x)$ at $a$ and $b$, but also the derivative $f'(x)$ at both points, then you need the 1st-order two-point polynomial, which would be a 3rd degree polynomial. Any 3rd-degree polynomial that passes through $(a,f(a))$ and $(b,f(b))$ can be written in the form $$P(x) = L_{a,b}(x) + K(x-a)(x-b)(x-c)$$ where the parameters $K$ and $c$ will be chosen in order to meet the other requirements. Specifically, if we take the derivative of $P(x)$ we get $$P'(x) = \frac{f(b)-f(a)}{b-a} + K\left((x-a)(x-b) + (x-a)(x-c) + (x-b)(x-c) \right)$$ so $$P'(a) = \frac{f(b)-f(a)}{b-a} + K(a-b)(a-c)$$ and $$P'(b) = \frac{f(b)-f(a)}{b-a} + K(b-a)(b-c)$$

so we have to solve the pair of equations $$\frac{f(b)-f(a)}{b-a} + K(a-b)(a-c) = f'(a)$$ $$\frac{f(b)-f(a)}{b-a} + K(b-a)(b-c) = f'(b)$$ for $K$ and $c$. The algebra is unpleasant but fairly straightforward.

If you want to match the 2nd derivatives also, you would need a 5th degree polynomial. I hesitate to work out the details as they are rather ugly, but the method generalizes more or less directly.

Since you don't ask for the approximation to be continuous why bother? I would split interval $[a,b]$ in two, $[a,b] = [a,\frac{a+b}{2}] \cup [\frac{a+b}{2} , b]$, and then define $$g|_{[a,\frac{a+b}{2})} (x) = f(a) + f'(a)(x-a) + \frac{f''(a)}2 (x-a)^2+...$$ $$g|_{(\frac{a+b}{2}),b]} (x) = f(b) + f'(b)(x-b) + \frac{f''(b)}2 (x-b)^2+...$$

so in each semiopen interval I apply the Taylor approximation. To conclude the construction just put $g(\frac{a+b}2)$ equal to the right or left limit as you prefer.

Obviously $g$ will have a discontinuity at $\frac{a+b}2$, but nevertheless it satisfies all your requests.