# How to find a Newton-Cotes formula with weights?

I want to build a Newton-Cotes formula with weights

$\int_0^1f(x)x^\alpha dx = a_0f(0) + a_1f(1) + R(f), \alpha > -1$

But, I cannot find any example, moreover I don't really know where to search or start either.

And, after I have the formula, how could I show that it makes sense and how could I find an expression for the error using an adequate derivative of f?

I need the formula and the error expression to find a formula for

$\int_0^{h} g(t)t^\alpha dt$, for a small h > 0

The idea behind Newton-Cotes rule is basically interpolation of the integrand. In case of weighted formula, we can interpolate only $f(x)$.
The interpolation nodes for Newton-Cotes are equally spaced and contain endpoints. Writing $f(x)$ interpolant in terms of Lagrange basis interpolants we have $$f(x) \sim P(x) \sum_{i = 1}^{K} f(x_i) \ell_i(x),$$ where $x_i = a + \frac{i-1}{K-1}(b-a)$ is a set of evenly spaced $K$ points spanning the $[a,b]$ interval and $\ell_i(x)$ is defined as $$\ell_i(x) = \prod_{j \neq i} \frac{x - x_j}{x_i - x_j}$$ Substituting $P(x)$ for $f(x)$ in the integral $$\int_a^b f(x) x^\alpha dx \approx \int_a^b P(x) x^\alpha dx = \sum_{i=1}^K w_i f(x_i)$$ with $w_i$ being $$w_i \equiv \int_a^b \ell_i(x) x^\alpha dx.$$ The interpolation error could be roughly estimated as $$\left|P(x) - f(x)\right| \leq \frac{1}{K!}\max\limits_{z \in [a,b]} \left|f^{(K)}(z)\right| \left|\prod_{i=1}^K (x-x_i)\right|$$ therefore quadrature error is bounded by $$\varepsilon = \left|\int_a^b (f(x) - P(x))x^\alpha dx\right| \leq \int_a^b \left|f(x) - P(x)\right| x^\alpha dx \leq \frac{1}{K!}\max\limits_{z \in [a,b]} \left|f^{(K)}(z)\right| \int_a^b \left|\prod_{i=1}^K (x-x_i)\right| x^\alpha dx$$
For your case $K = 2$ and $a = 0, b = 1$. Lagrange basis polynomials are $\ell_1 = 1 - x$ and $\ell_2 = x$, so $$w_1 = \int_0^1 (1-x)x^\alpha dx = \frac{1}{\alpha ^2+3 \alpha +2}\\ w_2 = \int_0^1 x \cdot x^\alpha dx = \frac{1}{\alpha + 2}\\ \varepsilon \leq \frac{1}{2}\max\limits_{z \in [a,b]} \left|f''(z)\right| \int_0^1 |(x-0)(x-1)| x^\alpha dx = \\ = \frac{1}{2}\max\limits_{z \in [a,b]} \left|f''(z)\right| \int_0^1 x(1-x) x^\alpha dx = \frac{1}{12+10\alpha +2\alpha^2}\max\limits_{z \in [a,b]} \left|f''(z)\right|$$ There are more precise ways to esimate quadrature errors, ask if you need them.
Simple test case. Let $\alpha = \frac{1}{2}$, $f(x) = \cos x$. $$w_1 = \frac{4}{15}, \qquad w_2 = \frac{6}{15}\\ \int_0^1 \cos x\sqrt{x} dx = 0.5312026830...\\ \sum_{i=1}^2 w_i f(x_i) = w_1 \cos 0 + w_2 \cos 1 = 0.4827875890...$$ The actual error is $\varepsilon = 0.048415$ and the error estimate is $$\varepsilon \leq \frac{2}{35} \max\limits_{z \in [0, 1]} \left|-\cos z\right| = \frac{2}{35} \approx 0.0571429.$$