Numerical Optimal Control (online)

Prof. Dr. Moritz Diehl -

The course’s aim is to give an introduction into numerical methods for the solution of optimal control problems in science and engineering. The focus is on both discrete time and continuous time optimal control in continuous state spaces. It is intended for a mixed audience of students from mathematics, engineering and computer science.



  • Date&Time: 19.8.2020, 9am
  • Location: Georges-Köhler-Allee 101, HS 00-026, HS 00-036, SR 00-010/14
  • Time for writing: 2h
  • Further details see "Final evaluation" below



Structure of the course

The course is organized as an online lecture and we provide recordings of the lecture and of the exercise solutions. Nonetheless we will meet once a week. This course has 6 ECTS credits. It is possible to do a project to get an additional 3 ECTS, i.e., a total of 9 ECTS for course+project. For more information please contact Florian Messerer.

Virtual meetings: We will meet every Friday in a virtual lecture room. These meetings are alternatingly dedicated to either Q&A sessions with Prof. Diehl or exercise sessions with the teaching assistant (see below). We will use Zoom for the meetings. Please note that you can join the meeting via your browser and do not need to install to the Zoom client. You can join via this link (browser) or this (client) (Meeting ID: 98903530867). The password is 7zgjKJapQ. Except for the kick-off session, none of the meetings will be recorded. For more information on how the university uses Zoom, a guide for students, and a note on data protection please see here (sorry, so far this page seems to exist in german only. Please let us know if you have any questions regarding the content).

Lecture recordings: The lecture recordings were already created in a past semester. There are 20 lectures of approximately 90 minutes each, which amounts to a lecture load of about 2 lectures or 3 hours per week. You can find a recommended schedule for watching them as well as the links in the calender below.

Course manuscript: The lectures are accompanied by a detailed course manuscript, which you may find in the materials section below. Please note that it is in general more detailed than the lectures and that we skip some of the chapters. Around 2 weeks after the start of the semester we will provide printed copies (for free).

Exercises: The exercises are mainly computer based. Computers with MATLAB and CasADi installed are required to solve them (see below for details). There will be a total of 10 exercises. They will be published throughout the semester, after some time delay followed by a solution manuscript as well as a video recording. The exercises are voluntary (though of course we strongly recommended to solve them). Nonetheless we offer the possibility to hand them in to receive feedback, but for this please respect the deadlines you can find in the calendar below. If you would like feedback on a specific part of the exercise especially, you can state so on your solution sheet.

Q&A sessions: Every second week there will be a virtual Q&A session with Prof. Diehl, where you can ask any questions about the course content. The format is meant to be highly interactive and depends strongly on your participation. We would recommend that while watching the video lectures or reading the course script, you write down any questions that come to your mind, such that you have them readily available for the Q&A sessions.

Exercise sessions: Every other week we will meet for the exercise sessions. They will not be used to show the solutions, but to discuss any questions related to the exercises. These can either be questions about the current exercise sheet or questions about the solution to the last sheet. As the Q&A sessions, this format depends heavily on your participance.

Forum: On Ilias, we provide a forum for discussion of any questions you have related to the course, be it organization, content or exercises. Please feel free to open new topics and to answer questions of your fellow students. You can join via this link.

Final evaluation: The final exam is a written closed book exam. Only pencil, paper, a calculator and two A4 sheets (i.e., 4 pages) of self-chosen content are allowed (handwritten). For students from the faculty of engineering and the B.Sc. Math, this exam is graded. Students from the M.Sc. Math need to pass the written exam in order to take the graded 11ECTS oral exam.

Projects: The optional project (3 ECTS) consists in the formulation and implementation of a self-chosen problem of Numerical Optimal Control, resulting in documented computer code, a project report, and a public presentation. Project work starts in the last third of the semester. Checkout the project guidelines below for more detail. For students from the faculty of engineering the project is graded independently from the 6ECTS lecture. For students from the B.Sc. Math, the grade for the lecture&project 9ECTS module is solely determined by the written exam. For students from the M.Sc. Math the project is again a prerequisite to the graded 11ECTS oral exam.



We will meet on the following fridays. All meetings are held virtually via Zoom (see above), but except for the kick-off meeting, none of the meetings will be recorded. For lecture 1, there is no recording. The chapters refer to the course manuscript from the material section below.

 Date  Time  Format  To prepare (watch)  To prepare (read)  Hand in
 15.5.  2pm  kick-off  first 10 minutes of this talk (section "embedded optimization")    
 22.5.  2pm  Q&A  lecture 2, lecture 3, lecture 4*  chap. 1 to 3.2  ex1 (voluntary)
 29.5.  2pm  exercise  solution ex1  
 05.6.  10am  Q&A  lecture 5, lecture 6lecture 7, lecture 8  chap. 3.3 to 5.4  ex2.pdf ex3.pdf (voluntary)
 12.6.  10am  exercise  solution ex2, ex3  
 19.6.  10am  Q&A - (open air, if weather is nice)  lecture 9, lecture 10, lecture 11, lecture 12

 chap. 7 to 8.8 (skip 6)

 ex4.pdf,, ex5.pdf (voluntary)
 26.6.  10am  exercise  solution ex4, ex5  
 03.7.  10am  Q&A  lecture 13, lecture 14, lecture 15, lecture 16  chap. 8.9 to 11  ex6.pdfex6.zipex7.pdf (voluntary)
 10.7.  10am  exercise  solution ex6, ex7  
 17.7.  10am  Q&A / projects  lecture 17, lecture 18, lecture 19, lecture 20

 chap. 12 to 16 (skip 14&17)

 ex8.pdfex9.pdf (voluntary)
 24.7.  10am  exercise  solution ex8, ex9  ex8_sol.pdf  
 31.7.  10am  Q&A / projects      ex10.pdf (voluntary)
 14.8.  10am  project pres  Project presentations  
 28.8.  11.59pm   ***  Deadline project report    project report

* The last 10 minutes of lecture 4 are mute


  • Manuscript of Numerical Optimal Control by S. Gros and M. Diehl (Draft)
  • Biegler, L. T., Nonlinear Programming, SIAM, 2010
  • Betts, J., Practical Methods for Optimal Control and Estimation Using Nonlinear Programming, SIAM, 2010
  • Rawlings, J. B., Mayne D. Q., Diehl, M., Model Predictive Control, 2nd Edition, Nobhill Publishing, 2017 (free PDF here)
  • Sample exams
  • Lecture recordings (with content overview)
    • Lecture 1 - Introduction (Not recorded)
    • Lecture 2 - Chapter 1.2 Continuous time Systems to Chapter 2.1 Local Convergence Rates
    • Lecture 3 - Chapter 2.2 Local Contraction to Chapter 2.5 Globalization
    • Lecture 4 - Chapter 3 Nonlinear Optimization to Chapter 3.2 First Order Optimality Conditions 
    • --note: in Lecture 4 the microphone's battery died at the end of the lecture, so the last 10 minutes are mute.
    • Lecture 5 - Chapter 3.3 Second Order Optimality Conditions to Chapter 4.1 Equality Constraint Optimization
    • Lecture 6 - Chapter 3.3 Second Order Optimality Conditions (recall) to Chapter 4.2 Local Convergence of Newton-Type Methods 
    • Lecture 7 - Chapter 4.3 Inequality Constrained Optimization to Chapter 4.4 Globalisation Strategies
    • Lecture 8 - Chapter 5 Derivatives to Chapter 5.4 Algorithmic Differentiation Software
    • Lecture 9 - Chapter 7 Discrete Optimal Control to Chapter 7.3 Sparsity Structure
    • Lecture 10 - Chapter 7.3 Sparsity Structure
    • Lecture 11 - Chapter 8 Dynamic Programming to Chapter 8.3 Infinite Horizon Problems
    • Lecture 12 - Chapter 8.3 Infinite Horizon Problems to Chapter 8.8 A Discrete Time Minimum Principle
    • Lecture 13 - Chapter 8.9 Differential Dynamic Programming
    • Lecture 14 - Chapter 9 Continuous Time Optimal Control to Chapter 10.2 Implicit Integration
    • Lecture 15 - Chapter 10.2 Implicit Integration  to end Chapter 10
    • Lecture 16 - Talk by Michael Neunert and Chapter 11 Hamilton Jacobi Bellman Equation
    • Lecture 17 - Chapter 12 Pontryagin and the Indirect Approach
    • Lecture 18 - Chapter 13 Direct Approaches
    • Lecture 19 - Chapter 15 Model Predictive Control
    • Lecture 20 - Chapter 16 Parametric Nonlinear Optimization


The project guidelines can be found here. We will dedicate some parts of later Q&A sessions to project work (voluntary, though strongly recommended). The aim on July 17th will be to finalize your project ideas into concrete projects (though you are welcome to work ahead and contact us already earlier). On July 31st the focus are the challenges you encounter along the way of solving your project. Be prepared to give short, informal presentations of your project idea and current state of progress.

Matlab and CasADi installation

MATLAB is an environment for numerical computing based on a proprietary language that allows one to easily manipulate matrices and visualize data which will be very helpful in prototyping the algorithms presented during the lectures of this course. The University of Freiburg offers a free-of-cost license to students and staff which can be obtained following the instructions here. In order to be able to complete the exercises of this course, you will need a working installation of MATLAB. Follow the instructions at the provided link in order to install the software package.
CasADi is a symbolic framework for algorithmic differentiation and numerical optimization. In order to install CasADi, follow the instructions here. Download the binaries for your platform and, after having extracted them, add their location to MATLAB's path. To test your installation run the simple example described at the provided link. If successful, save the path by executing the command savepath. In this way, the location of the binaries will be known even after restarting MATLAB.