Optimal Reference Shaping for Dynamical Systems