MATLAB Examples

This document explains how to use the setup function and online controller returned by ssmpcsetup.

This document explains how to use the DMC Simulink block.

Dynamic Matrix Control (DMC) was the first Model Predictive Control (MPC) algorithm introduced in early 1980s. Nowadays, DMC is available in almost all commercial industrial distributed

Control a double integrator plant under input saturation in Simulink®.

Design model predictive controller with one measured output, one manipulated variable, one measured disturbance, and one unmeasured disturbance in a typical workflow.

Design a model predictive controller by first from linearizing a nonlinear plant in Simulink® .

Design a model predictive controller for a multi-input multi-output nonlinear plant. The plant has 3 manipulated variables and 2 measured outputs.

Design a model predictive controller with non-zero nominal values.

Uses a model predictive controller (MPC) to control an inverted pendulum on a cart.

How create and test a model predictive controller from the command line.

Use an Adaptive MPC controller to control a nonlinear continuous stirred tank reactor (CSTR) as it transitions from low conversion rate to high conversion rate.

Use the docid:mpc_ref#mw_b6137087-34df-4886-a19f-85d7b7612bbf block in Simulink® and demonstrates the control objectives and constraints of this block.

Make a vehicle (ego car) follow a reference velocity and avoid obstacles in the lane using adaptive MPC. To do so, you update the plant model and linear mixed input/output constraints at run

Simulate and generate code for an automotive lane keeping assist (LKA) controller.

Implement a sensor fusion based automotive adaptive cruise controller for a vehicle traveling on a curved road using sensor fusion.

Use the docid:mpc_ref#mw_13041e31-f545-4d5d-98bd-f9106dc52239 block in Simulink® and demonstrates the control objectives and constraints of this block.

Implement an online model predictive controller application using the OPC client supplied with the OPC Toolbox™.

Simulate and generate real-time code for an MPC Controller block with Simulink Coder. Code can be generated in both single and double precisions.

Configure and simulate MPC Controller blocks placed inside Function-Call and Triggered subsystems.

Simulate and generate Structured Text for an MPC Controller block using PLC Coder software. The generated code uses single-precision.

Use the docid:mpc_ref.bu5k6ul command to generate C code to compute optimal MPC control moves for real-time applications.

Use non-diagonal weight matrices in a model predictive controller.

Design model predictive controller with mixed input/output constraints.

Inspect the optimized sequence of manipulated variables computed by model predictive controller at each sample time.

Use the review command to detect potential issues with a model predictive controller design.

Specify scale factors in MPC controller to make weight tuning easier.

Simulate a model predictive controller under a mismatch between the predictive plant model and the actual plant.

Design a model predictive controller for a plant with two inputs and one output with target setpoint for a manipulated variable.

Design an infinite-horizon model predictive controller by setting the weights on the terminal predicted states.

Compute numerical derivatives of a closed-loop cumulated performance index with respect to weights and use them to improve model predictive controller performance.

Uses a nonlinear model predictive controller (nonlinear MPC) to achieve swing-up and balancing control of an inverted pendulum on a cart.

Maximize the production of an ethylene oxide plant for profit using an economic MPC controller with custom cost and constraint functions.

Use a nonlinear model predictive controller (nonlinear MPC) to control an ethylene oxidation plant as it transitions from one operating point to another.

Use Explicit MPC to control DC servomechanism under voltage and shaft torque constraints.

Uses an explicit model predictive controller (explicit MPC) to control an inverted pendulum on a cart.

Control a double integrator plant under input saturation in Simulink® using explicit MPC.

Control an unstable aircraft with saturating actuators using explicit model predictive control.

Use multiple MPC controllers to control a nonlinear continuous stirred tank reactor (CSTR) as it transitions from low conversion rate to high conversion rate.

Uses a gain-scheduled model predictive controller to control an inverted pendulum on a cart.

Use an Multiple MPC Controllers block and an Multiple Explicit MPC Controllers block to implement gain scheduled MPC control of a nonlinear plant.

If your plant is nonlinear, a controller designed to operate in a particular target region may perform poorly in other regions. A common way to compensate is to create multiple controllers,

Control an unstable aircraft with saturating actuators.

Control a thermo-mechanical pulping (TMP) plant with a model predictive controller.

Design a model predictive controller in MATLAB for a high-fidelity distillation tower model built in Aspen Plus Dynamics®. The controller performance is then verified through

Use constraints on a combination of inputs and outputs to control a nonlinear blending process.

Design a model predictive controller for a DC servomechanism under voltage and shaft torque constraints.

How the Model Predictive Control Toolbox™ can use time-varying prediction models to achieve better performance when controlling a time-varying plant.

Control an inverted pendulum on a cart using a linear time-varying model predictive controller (LTV MPC).

Design a model predictive controller at the command line using an identified plant model.

Design an MPC controller for a blending process using custom input and output constraints.

Shows how to design an unconstrained MPC controller that provides performance equivalent to an LQR controller.

Analyze a model predictive controller using docid:mpc_ref.f2-8236 . This function computes the closed-loop, steady-state gain for each output when a sustained, 1-unit disturbance is

Obtain an LTI representation of an unconstrained MPC controller using docid:mpc_ref.f2-23723 . You can use this to analyze the frequency response and performance of the controller.

Use the built-in QP solver to implement a custom MPC control algorithm that supports C code generation in MATLAB.

You can simulate the closed-loop response of an MPC controller with a custom quadratic programming (QP) solver in Simulink®.

Guarantee the worst-case execution time of an MPC controller in real-time applications by using the suboptimal solution returned by the optimization solver.

Simulate and generate code for a model predictive controller that uses a custom quadratic programming (QP) solver. The plant for this example is a dc-servo motor in Simulink®.

Obtain a linear model of a plant using a MATLAB script.

Identify a plant model at the command line. For information on identifying models using the System Identification app, see docid:ident_gs.bqs6ip8 .

Vary the weights on outputs, inputs, and ECR slack variable for soft constraints in real-time.

Design a model predictive controller with look-ahead (previewing) on reference and measured disturbance trajectories.

Vary input and output saturation limits in real-time control. For both command-line and Simulink® simulations, you specify updated input and output constraints at each control interval.

Obtain bumpless transfer when switching model predictive controller from manual to automatic operation or vice versa.

Use the "qp.status" outport of the MPC Controller block in Simulink® to detect controller failures in real time.

Use measurable plant states in MPC control at run time.

Use the "optimal cost" outport of the MPC Controller block to switch between multiple model predictive controllers whose outputs are restricted to discrete values.

Choose your country to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a location from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.