The generalized discrete variable representation. An optimal design