# Quadrature rules exact for given functions

Many quadrature schemes are defined by the degree of polynomials for which they are exact. For example, we say that the rule $\sum_i a_i f(x_i)$ is order $n$ when $\sum_i a_i p(x_i) = \int p(x) dx$ for all polynomials $p$ of degree $\leq n$.

My question is whether or not there is some body of known results and techniques for deriving quadrature rules that are exact for some arbitrary set of functions. Mainly, I'm thinking about how to derive rules that are exact for all polynomials of degree $\leq n$ and exact for a few other given functions $f(t)$, $g(t)$, and $h(t)$, say.

I would guess that one could optimally use $m$ points and be of order $2m-k$ and also exact for $k$ functions generically, but I haven't the faintest clue if someone has already worked out how one derives such rules or whether such rules have a name.

Yes, such rules can be derived in the same way that is done for polynomials. Given arbitrary basis functions $\phi_i(x)$, the quadrature rule $$\int f(x) dx \approx \sum_i c_i f(x_i)$$ will be exact for linear combinations of the basis functions if we take the weights as the solution of the following linear system:
$$\begin{pmatrix} \phi_1(x_1) & \phi_1(x_2) & \cdots & \phi_1(x_n) \\ \vdots & \vdots & & \vdots \\ \phi_n(x_1) & \phi_n(x_2) & \cdots & \phi_n(x_n) \end{pmatrix} \begin{pmatrix} c_1 \\ \vdots \\ c_n \end{pmatrix} = \begin{pmatrix} \int \phi_1 \\ \vdots \\ \int \phi_n \end{pmatrix}.$$