I hope that numerical questions are also permitted here.


I want to expand a smooth functions $f \in C^{\infty}$in terms of Legendre polynomials. Thus I need to calculate integrals of the form $\int\_{-1}^{1} f(x) P\_n(x)$, where $n$ becomes sufficiently large (between 40 and 80). In that regime, the Legendre polynomials oscillate heavily, so my question is whether you are aware of a particular method that is good for integrating such things, cause the standard MATLAB method ( probably some low-level Newton Cotes method) cannot do it sufficiently accurate. 


Although this is not a pure math question, I think that this question is of some particular value in applications, so please be not to hard with me ;-)



Numerical integration of legendre polynomials
It seems fundamentally ill-conditioned.


Since $\int\_{-1}^{+1} x^rP\_n(x),dx=0$ for $r=0,1,\dots,n-1$, your integral is unchanged if you subtract a polynomial of degree $n-1$ from $f(x)$. I'm guessing that if you can do that very accurately for some polynomial that approximates $f(x)$, the resulting integral won't be so ill-conditioned as the original.


