Optimal Spectral-Galerkin Methods Using Generalized