Optimal trajectories of open-chain mechanical systems