Source: https://www.ucl.ac.uk/~uctp041/Teaching_files/TutorialDynOpt.pdf