File Exchange

image thumbnail

Stochastic Model Predictive Control Toolbox

version 1.0.7 (155 KB) by Edwin Alonso González Querubín
Stochastic model predictive control (chance-constrained and scenario based) simulator for linear systems with additive disturbances.


Updated 05 Mar 2021

View Version History

View License

Most stochastic MPC's can be classified within two groups: In the first group are those based in analytical methods (Chance-Constrained), which solve an OCP based on the expected value of an index cost, subject to probabilistic constraints, generally in the predicted states. In the second group are those based on random scenarios (Scenario-Based), which solve an OCP for a determined number of random realizations of uncertainties also called scenarios.

The files contain a basic Stochastic predictive control simulators for multivariable linear systems with additive disturbances. The disturbances have a Gaussian probability distribution and can be bounded. In total there are two simulators: a simulator for an MPC based on chance constraints for states; and another based on scenarios of realizations of the disturbances. In addition, for each controller there are files with examples based on a two-mass spring system implementation.

Please, before starting to use it, read the file "readme.txt"

Author: Edwin Alonso González Querubín
Research Group: Predictive Control and Heuristic Optimization (CPOH)
Unversity: Universidad Politécnica de Valencia

For more details about the stochastic predictive control algorithms implemented here, please consult the article associated with this toolbox:

Cite As

Edwin Alonso González Querubín (2021). Stochastic Model Predictive Control Toolbox (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (12)

Hi Mehmet Ozkan, you can do it by including the mean value of the uncertainty in the deterministic part of the system model. maybe this document will help you


Hi Adesola Bankole, i have simulated the files and it works fine. Maybe it's your version of matlab that doesn't include such a command (xticklabels). You can try commenting that line (lines 109 and 125) in the code.


Adesola Bankole

Nice toolbox.
Please, I tried running the example under scenario based mpc, that is, the main.m. It worked fine until it got to line 109.

The error it gave me is:
Undefined function or variable 'xticklabels'.
As a result, it couldn't plot the graphs. Only the graph of the real state evolution was plotted.

Please, kindly reply to know what I can do.

Thank you sir

Mehmet Ozkan

How the chance constraint implementation will be different if the mean of the Gaussian distribution is non-zero?

Hi Himanshu Nagpal, I recommend you articles like

Also, very soon, here I will put as a reference an article of my authorship, which is pending publication.

Regarding the variable "var", it is not zero as you say. This corresponds to the initial variance for that specific problem, and is zero for states 1 and 2 but has a value for states 3 and 4: var = blkdiag (0, 0, 0.022, 0.022).


Himanshu Nagpal

Great Toolbox! Thanks for this.

Could you please provide documentation on which this code is based upon? It would be a great help.

Question - Why did you not choose "var" to be a matrix of all 0's in the Chance-Constraint example?

haisong zhao

What literature is the basis for the formula in your code? Can you share these literature or books?

haisong zhao

Hello, Edwin Alonso González querubín, thank you for sharing the code. Your example 'chance_constraint_MPC' doesn't seem to work. For a two-mass spring system, the matrix A you give seems to be wrong. When I run the example based on scenario emuation, matlab is always in "busy" and there is no simulation result.

Hello Lecheng Wang, maybe it takes a while because you have put many moments (you say that for a whole day), so added to the number of states, horizon of prediction and desired probability of success; the simulation will take much longer. Remember that the code is made to show the graphs once the simulation has finished (that's why it shows you that it is busy). regards

Lecheng Wang

when I run the example based on scenario emuation for one day, matlab is always in "busy" and there is no simulation result

Stephen Forczyk, you must fill that file with the information of your process. There is an example. Please read the end of the file "readme.txt"

Stephen Forczyk

Could not get your script to run as delivered. Get thee errors
% Initial state and Kalman filter
% x0: is the initial system state and must be size nx_X_1
% P0: is initial state covariance for Kalman filter to estimate the states
% of the system and must be size nx_X_nx. If you prefer to use the real
% states of the system, make P0 = NaN
x0 = ; Matlab does not like this!!!!!!
P0 = ;

MATLAB Release Compatibility
Created with R2020a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!