Two - point weighted - average rule

soln=Solve[{b-a==w0+w1,(b^2-a^2)/2==w0*x0+w1*x1,(b^3-a^3)/3==w0*x0^2+w1*x1^2,(b^4-a^4)/4==w0*x0^3+w1*x1^3},{w0,w1,x0,x1}]

s=soln[[2]]/.{a->-1,b->1}

f[x_]:=a x^3+b x^2+c x+d;

Integrate[f[x],{x,-1,1}]

Expand[Simplify[(w0 f[x0]+w1 f[x1])/.s]]

Gaussian quadrature rule for 2 points using w(x) = x

soln=Solve[{1/2==w0+w1,1/3==w0*x0+w1*x1,1/4==w0*x0^2+w1*x1^2,1/5==w0*x0^3+w1*x1^3},{w0,w1,x0,x1}]

N[soln[[2]]]

f[x_]:=a x^3+b x^2+c x+d;

Integrate[x f[x],{x,0,1}]

Expand[Simplify[(w0 f[x0]+w1 f[x1])/.soln[[2]]]]

g[x_]:=x^4+ x^3+ x^2+x+3;
N[Integrate[x g[x],{x,0,1}]]

N[(w0 g[x0]+w1 g[x1])/.soln[[2]]]

Legendre Polynomials

p0[x_]:=1;
p1[x_]:=x;

x^2-Integrate[p0[x]x^2,{x,-1,1}]/Integrate[p0[x]^2,{x,-1,1}]p0[x]-Integrate[p1[x]x^2,{x,-1,1}]/Integrate[p1[x]^2,{x,-1,1}]p1[x]

p2[x_]:=x^2-1/3

x^3-Integrate[p0[x]x^3,{x,-1,1}]/Integrate[p0[x]^2,{x,-1,1}]p0[x]-Integrate[p1[x]x^3,{x,-1,1}]/Integrate[p1[x]^2,{x,-1,1}]p1[x]-Integrate[p2[x]x^3,{x,-1,1}]/Integrate[p2[x]^2,{x,-1,1}]p2[x]

p3[x_]:=x^3-3x/5

w0=Integrate[(x-1/Sqrt[3])/(-2/Sqrt[3]),{x,-1,1}]
w1=Integrate[(x+1/Sqrt[3])/(2/Sqrt[3]),{x,-1,1}]

Last example with w(x)=x on [0,1]

p0[x_]:=1;

x-Integrate[x p0[x]x,{x,0,1}]/Integrate[x p0[x]^2,{x,0,1}]p0[x]

p1[x_]:=x-2/3

Simplify[x^2-Integrate[x p0[x]x^2,{x,0,1}]/Integrate[x p0[x]^2,{x,0,1}]p0[x]-Integrate[x p1[x]x^2,{x,0,1}]/Integrate[x p1[x]^2,{x,0,1}]p1[x]]

Roots[(3/10)-((6 x)/5)+(x^2)==0,x]

x0=(1/10) (6-(Sqrt[6]))
x1=(1/10) (6+(Sqrt[6]))

w0=Integrate[x(x-x1)/(x0-x1),{x,0,1}]
w1=Integrate[x(x-x0)/(x1-x0),{x,0,1}]