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:
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)$
Ideally: g(x) should be simple, easily integrable, analytically tractable, and (just like Taylor approximation) allow for arbitrary degrees of precision. Preferably polynomial.
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.
We care whether the integrals of $f(x)$ and $g(x)$ on $[a,b]$ are approximately equal for arbitrary functions $f(x)$.
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"?
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.