2nd vs. 3rd Order Gauss Quadrature

numerical methods

I have read that using Gauss Quadrature integration,
$$\int_{-1}^{1}f(x)dx=\sum_i f(x_i)w_i$$
for polynomials of degree $\leq2n-1$ (and otherwise it is an approximation). Using weight functions $w_i$ from wikipedia, for 2$^{nd}$ order GQ we have
$$\int_{-1}^{1}f(x)dx=f\bigg(\frac{1}{\sqrt{3}}\bigg) + f\bigg(-\frac{1}{\sqrt{3}}\bigg)$$
and for 3$^{rd}$ order,
$$\int_{-1}^{1}f(x)dx=\frac 59 f\bigg(\sqrt{\frac{3}{5}}\bigg)+ \frac 59 f\bigg(-\sqrt{\frac{3}{5}}\bigg) $$

My problem is that I don't seem to be getting the same answer for second and third order GQ for polynomials of degree $\leq 3$, for which they should both yield exact solutions.

For example, for the function $f(x)=a_1 + a_2x + a_3x^2 + a_4x^3$, from first order GQ I get:
$$\int_{-1}^{1}f(x)dx=2a_1 + \frac{2}{3}a_3$$
which I believe is the correct solution, but for third order GQ I get

$$\int_{-1}^{1}f(x)dx=\frac{10}{9}a_1 + \frac 23 a_3$$

This error seems to occur for any constant term in any polynomial as a result of the fact that the sum of the weight functions aren't equal for second and third order GQ. Why is this? I can't find my mistake!

Thanks in advance for your help.

Best Answer

For 3 point quadrature I believe you are missing $\frac{8}{9} f(0)$ in your sum.

It would also introduce a $\frac{8}{9}a_{1}$ which would correct your toy example.