A least-squares method for residence time distribution analysis