## 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. For more information about using the FORCESPRO NLP solver with nonlinear MPC controllers, see Implement MPC Controllers Using Embotech FORCESPRO Solvers.

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 has 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 functions only of the decision variables and parameters at that stage. Other than make it easier to write Jacobian functions, this feature allows for a much more efficient data structure, which in turn significantly reduces computation times compared to the same problem solved using a generic NLMPC controller. The fact that slack variables are stage-based allows for more design flexibility, and disabling the use of manipulated variable rates as decision variables yields an even leaner problem formulation.

For these reason, if your nonlinear MPC problem has cost and constraint functions that do not involve cross-stage terms, and if you do not need to enforce passivity, 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.

• Specifying Jacobians when they are available is the best practice, 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 a multistage MPC controller, see Create and Simulate Multistage Nonlinear MPC Controller, Simulate Multistage Nonlinear MPC Controller Using Initial Guesses, and Truck and Trailer Automatic Parking Using Multistage Nonlinear MPC.