Copied basisFit code from kevrekidis package.