Model Predictive Control textbook cover

Figures from
Model Predictive Control: Theory, Computation, and Design

2nd Edition

James B. Rawlings Department of Chemical Engineering University of California, Santa Barbara
David Q. Mayne Department of Electrical and Electronic Engineering Imperial College London
Moritz M. Diehl Department of Microsystems Engineering University of Freiburg

Click on thumbnails to enlarge figures and display Python code and data. You will also need a few files (mostly for plotting) that are included only in the zip files below, so if you want to run them, the best thing to do is download the complete collection of .py-files. Having the code linked here is still useful if you want to take a quick look at how something is done.

Running the example files requires Python (version 3.10 or later), as well as CasADi (version 3.0 or later; download here) and MPCTools (download here). Installation instructions can be found on the respective websites.

Python download:

Octave/Matlab legacy code (current as of 12/2024; no longer maintained):

Chapter 2: Model Predictive Control — Regulation