## Nonlinear MPC

As in traditional linear MPC, nonlinear MPC calculates control actions at each control interval using a combination of model-based prediction and constrained optimization. The key differences are:

• The prediction model can be nonlinear and include time-varying parameters.

• The equality and inequality constraints can be nonlinear.

• The scalar cost function to be minimized can be a nonquadratic (linear or nonlinear) function of the decision variables.

Using nonlinear MPC, you can:

• Simulate closed-loop control of nonlinear plants under nonlinear costs and constraints.

• Plan optimal trajectories by solving an open-loop constrained nonlinear optimization problem.

By default, nonlinear MPC controllers solve a nonlinear programming problem using the `fmincon` function with the SQP algorithm, which requires Optimization Toolbox™ software. If you do not have Optimization Toolbox software, you can specify your own custom nonlinear solver. For more information on configuring the `fmincon` solver and specifying a custom solver, see Configure Optimization Solver for Nonlinear MPC.

Note

The MPC Designer app does not support the design of nonlinear MPC controllers.

### Generic Nonlinear MPC

To implement generic nonlinear MPC, create an `nlmpc` object, and specify:

You can simulate generic nonlinear MPC controllers:

### Multistage Nonlinear MPC

A multistage MPC problem is an MPC problem in which cost and constraint functions are stage-based. Specifically, a multistage MPC controller with a prediction horizon of length p has p+1 stages, where the first stage corresponds to the current time, and the last (terminal) stage corresponds to the last prediction step.

For a multistage MPC controller, each stage can have its own decision variables and parameters, as well as its own nonlinear cost and constraints. More importantly, cost and constraint functions at a specific stage are only functions of the decision variables and parameters at that stage. This feature allows for a much more efficient data structure and formulation of the underlying nonlinear programming problem, which significantly reduces computation times compared to the same problem solved using a generic NLMPC controller.

For this reason, if your nonlinear MPC problem has cost and constraint functions that do not involve cross-stage terms, you should use multistage nonlinear MPC controller in your design.

To implement a multistage nonlinear MPC controller, first create an `nlmpcMultistage` object, and then specify:

• State functions that define your prediction model. For discrete-time models, make sure `Model.IsContinuousTime` is set to `false`.

• Cost and constraint functions at the desired stages. You must specify the cost function for at least one stage.

• Hard upper and lower bounds on states, manipulated variables, and manipulated variable rates, if needed.

When designing your controller, consider the following points.

• Anonymous functions are not supported for `nlmpcMultistage` objects.

• It is best practice to specify Jacobians when they are available, otherwise the solver must compute them numerically at each step.

• Unlike in generic nonlinear MPC, plant outputs, weights, ECR values, and scale factors are not present in an `nlmpcMultistage` object. You can implement them directly in your cost and constraint functions.

• The control horizon is also omitted in `nlmpcMultistage` objects. To implement block moves, set `RateMin` and `RateMax` to zero at desired prediction steps.

You can simulate multistage nonlinear MPC controllers:

Code generation from a nonlinear multistage controller is supported in both MATLAB (using `mpcmoveCodeGeneration`) and Simulink.

For examples on how to create and use multistage MPC controller, see Create and Simulate a Multistage Nonlinear MPC Controller, Simulate a Multistage Nonlinear MPC Controller Using Initial Guesses and Truck and Trailer Automatic Parking Using Multistage Nonlinear MPC.