import numpy as np
import numpy.linalg as la
We found the integrals:
$$ \begin{align*} \int_0^1 1 dx &= 1\\ \int_0^1 x dx &= \frac 12 \\ \int_0^1 x^2 dx &= \frac 13 \\ \end{align*} $$integrals = np.array([1, 1/2, 1/3])
nodes = np.linspace(0, 1, 3)
nodes
V = np.array([
1+0*nodes,
nodes,
nodes**2
]).T
V
Now compute the weights:
la.inv(V).T.dot(integrals)