/* Approximate the integral integral of g(x) for x in [a,b] by subdividing the interval [a,b] into m subintervals of size delta, rescaling each subinterval to [-1,1] and applying the quadrature formula integral f(x) for x in [-1,1] = sum w[k] f(x[k]) and then summing the results over all the subintervals. Note: If you change the values of x[k] below, then you should also change the weights w[k] so that the equality integral x^j for x in [-1,1] = sum w[k] x[k]^j is exact for each j from 0 to K-1. */ #include #include #define K 4 double x[K]={ -3.0/4, -1.0/4, 1.0/4, 3.0/4 }; double w[K]={ /* Please fill in these values */ }; double g(double x){ return exp(-x*x); } double coats(double a,double delta){ double s=0.0; for(int k=0;k