1. A method for computing an optimized setpoint trajectory of an aircraft, executed by a flight management system, the trajectory defining at least successive values of lateral position, altitude, and speed of the aircraft, the trajectory comprising at least two subsets, the method comprising at least: a step of formulating at least one optimal control problem for the trajectory for at least one optimization criterion, the formulating step comprising at least: a sub-step of formulating at least one constraint of said at least one optimal control problem related to a transition of legs on at least one first subset of the trajectory; and a sub-step of formulating at least one constraint of said at least one optimal control problem related to a transition of vertical flight phases on at least one second subset of the trajectory; a step of solving the optimal control problem for the trajectory; and controlling an automatic pilot with the trajectory that was formulated using the solved optimal control problem.