% (inelegant) Matlab script to illustrate method of undetermined coefficients 
% to derive Simpson's rule
% i.e., a 3-point quadrature rule using abscissae a, (a+b)/2, b

clear all, close all

syms w1 w2 w3 a b

eq1 = w1*1 + w2*1 + w3*1 == b - a;

eq2 = w1*a + w2*(a+b)/2 + w3*b == (b^2 - a^2)/2;

eq3 = w1*a^2 + w2*((a+b)/2)^2 + w3*b^2 == (b^3 - a^3)/3;

[w1,w2,w3] = solve(eq1,eq2,eq3)
