An electric machine is provided. A polyphase machine is provided. A power inverter is electrically connected to the polyphase machine. A controller is electrically connected to the power inverter, wherein the controller provides switching signals to the power inverter, wherein the controller comprises a trajectory calculator that provides an optimized trajectory for transitioning the polyphase machine from a first torque to a second torque.