# gaussquad.jl -- Gaussian Quadrature on 4 Points
# these are the roots of the orthogonal polynomial in xs and
# the exact values of the integrals of x^j for j = 0,1,2,3
bs=[2,0,2/3,0]
xs=[-0.339981043584856,0.339981043584856,-0.861136311594053,0.861136311594053]
# construct the Vandermonde matrix and solve for the weights
V=xs' .^ [0:3;]
ws=V\bs
# test the method on log(x+2) and compute the error
f(x)=log(x+2)
exact=1.29583686600433
approx=ws'*f.(xs)
error=approx-exact