The important part of my question is after the bold "Now"
The method of undetermined coefficients is defined so that the error of a function $f(x)$ to be integrated is zero. I.e.
$E=\int_{a}^{b} f(x) dx - \sum_{i=0}^{n} A_i f(x_i) =0$
Where $f(x)$ is a polynomial of degree not exceeding $n$. Given this information you can construct a system of equations, solve it, and find what the coefficients $A_i$ are.
Your result is that $\int_{a}^{b} p_n(x) dx = \sum_{i=0}^{n} A_i p_n(x_i)$.
Now, this method is used to approximate other non-polynomial integrals. For example:
$\int_{0}^{2} cosh(x)dx$ is calculated by solving the augmented matrix (1) and taking points $(0,1),(1.0,cosh(1)),(2,cosh(2))$ to find ${A_0, A_2, A_3}$
(1) $\begin{bmatrix} 1 & 1 & 1 & 2-0 \\ 0 & 1 & 2 &(4-2)/2 \\ 0 & 1 & 4 & (8-0)/3 \end{bmatrix}$
And we get the that $\int_{0}^{2} cosh(x) dx \approx \frac{1}{3} cosh(0)+ \frac{4}{3} cosh(1) + \frac{1}{3} cosh(2) $ Which gives an error of $-0.0180$
Now, obviously the method works. But it seems magical to me. A method which was derived for polynomial functions, has applications to other types of functions... Why so?
Also, the derivation for polynomials has as a condition the fact that you have to be taking into consideration distinct $x_i$. Approximation to other complicated integrals seems to necessitate that this $x_i$ are within the interval of integration, otherwise the approximation isn't any good.
Whats going on here?
Why does this method work for non-polynomial functions, and why do the $x_i$ have to be within the interval of integration?