Boundary conditions in Chebyshev and Legendre methods