Coda suggested I put this here for easier viewing :P
This problem has to do with Gauss Quadrature, specifically one-point to five-point Gauss-Legendre formulas.
Here's the problem:
Write a function which computes the integral of a function handle f using the Gauss-Legendre quadrature rule. The function takes as input the function handle f to be integrated, number of Gauss-Legendre points n chosen for integration and the limits of integration a and b.
Refer the following link, to program the weights and points of Gauss-Legendre Quadrature from n = 1 until n = 5.
https://en.wikipedia.org/wiki/Gaussian_quadrature
And here's my
code so far.
I've split it into two parts: the first part of the if statement deals with cases where n is even, and the second where n is odd. (n is the number of points used in the quadrature, and corresponds to the row of both matrices.)
I've tried it against a test code and an example from the text, both where n = 3, and both passed. I tested the example with n = 4, and since Gauss quadrature is accurate to the third degree, and the solutions for n = 3 and n = 4 were the same, I'm reasonably certain that the first half is okay. However, using n = 5 for that example, the answer given didn't match the actual value of the integral, or the solutions for n = 3 and n = 4.
My code fails an assertion (test), but that test is hidden, so I'm not sure which part of my code is messing up. However, since the solution for n = 5 seems wrong, I'm assuming that might be it.