Main Content


Convert nlmpc object into one or more mpc objects


In practice, when producing comparable performance, linear MPC is preferred over nonlinear MPC due to its higher computational efficiency. Using the convertToMPC function, you can convert a nonlinear MPC controller into one or more linear MPC controllers at specific operating points. You can then implement gain-scheduled or adaptive MPC using the linear controllers and compare their performance to the benchmark nonlinear MPC controller. For an example, see Nonlinear and Gain-Scheduled MPC Control of an Ethylene Oxidation Plant.

To use convertToMPC, your nonlinear controller must not have custom cost or constraint functions, since these custom functions are not supported for linear MPC controllers.


mpcobj = convertToMPC(nlmpcobj,states,inputs) converts the nonlinear MPC controller object nlmpcobj into one or more linear MPC controller objects at the nominal conditions specified in states and inputs. The number of linear MPC controllers, N, is equal to the number of rows in states and inputs.

mpcobj = convertToMPC(nlmpcobj,states,inputs,MOIndex) specifies the indices of the measured outputs. Use this syntax when your controller has unmeasured output signals.

mpcobj = convertToMPC(nlmpcobj,states,inputs,MOIndex,parameters) specifies the values of prediction model parameters for each nominal condition. Use this syntax when your controller prediction model has optional parameters.


collapse all

Create a nonlinear MPC controller with four states, one output variable, one manipulated variable, and one measured disturbance.

nlobj = nlmpc(4,1,'MV',1,'MD',2);

Specify the controller sample time and horizons.

nlobj.PredictionHorizon = 10;
nlobj.ControlHorizon = 3;

Specify the state function of the prediction model.

nlobj.Model.StateFcn = 'oxidationStateFcn';

Specify the prediction model output function and the output variable scale factor.

nlobj.Model.OutputFcn = @(x,u) x(3);
nlobj.OutputVariables.ScaleFactor = 0.03;

Specify the manipulated variable constraints and scale factor.

nlobj.ManipulatedVariables.Min = 0.0704;
nlobj.ManipulatedVariables.Max = 0.7042;
nlobj.ManipulatedVariables.ScaleFactor = 0.6;

Specify the measured disturbance scale factor.

nlobj.MeasuredDisturbances.ScaleFactor = 0.5;

Compute the state and input operating conditions for three linear MPC controllers using the fsolve function.

options = optimoptions('fsolve','Display','none');

uLow = [0.38 0.5];
xLow = fsolve(@(x) oxidationStateFcn(x,uLow),[1 0.3 0.03 1],options);

uMedium = [0.24 0.5];
xMedium = fsolve(@(x) oxidationStateFcn(x,uMedium),[1 0.3 0.03 1],options);

uHigh = [0.15 0.5];
xHigh = fsolve(@(x) oxidationStateFcn(x,uHigh),[1 0.3 0.03 1],options);

Create linear MPC controllers for each of these nominal conditions.

mpcobjLow = convertToMPC(nlobj,xLow,uLow);
mpcobjMedium = convertToMPC(nlobj,xMedium,uMedium);
mpcobjHigh = convertToMPC(nlobj,xHigh,uHigh);

You can also create multiple controllers using arrays of nominal conditions. The number of rows in the arrays specifies the number controllers to create. The linear controllers are returned as cell array of mpc objects.

u = [uLow; uMedium; uHigh];
x = [xLow; xMedium; xHigh];
mpcobjs = convertToMPC(nlobj,x,u);

View the properties of the mpcobjLow controller.

MPC object (created on 26-Nov-2022 06:58:01):
Sampling time:      1 (seconds)
Prediction Horizon: 10
Control Horizon:    3

Plant Model:        
      1  manipulated variable(s)   -->|  4 states  |
                                      |            |-->  1 measured output(s)
      1  measured disturbance(s)   -->|  2 inputs  |
                                      |            |-->  0 unmeasured output(s)
      0  unmeasured disturbance(s) -->|  1 outputs |
  (input vector)    Manipulated variables: [1 ]
                    Measured disturbances: [2 ]
  (output vector)        Measured outputs: [1 ]

Disturbance and Noise Models:
        Output disturbance model: default (type "getoutdist(mpcobjLow)" for details)
         Measurement noise model: default (unity gain after scaling)

        ManipulatedVariables: 0
    ManipulatedVariablesRate: 0.1000
             OutputVariables: 1
                         ECR: 100000

State Estimation:  Default Kalman Filter (type "getEstimator(mpcobjLow)" for details)

 0.0704 <= u1 <= 0.7042, u1/rate is unconstrained, y1 is unconstrained

Input Arguments

collapse all

Nonlinear MPC controller, specified as an nlmpc object.


Your nlmpc controller object must not have custom cost or constraint functions.

Nominal state values, specified as an N-by-Nx array, where Nx is equal to nlmpcobj.Dimensions.NumberOfStates. Each row of States specifies a nominal set of states to be used in conversion.

The number of rows in states and inputs must match.

Nominal input values, specified as an N-by-Nu array, where Nu is equal to nlmpcobj.Dimensions.NumberOfInputs. Each row of Inputs specifies a nominal set of inputs to be used in conversion.

The number of rows in states and inputs must match.

Measured output indices, specified as a vector of length Ny, where Ny is the number of outputs. If MOIndex is [], every output is measured. Otherwise, any outputs not listed in MOIndex are unmeasured.

convertToMPC uses MOIndex to configure the default state estimators in mpcobj.

Prediction model parameter values, specified as an N-by-Np cell array, where Np is equal to nlmpcobj.Model.NumberOfParameters. Each row of parameters specifies the model parameter values for a given nominal condition. In each row, the order of the parameters must match the order specified in the model functions. Each parameter must be a numeric parameter with the correct dimensions; that is, the dimensions expected by the prediction model functions.

For each nominal condition, these parameters are passed to the state function (nlmpcobj.Model.StateFcn) and output function (nlmpcobj.Model.OutputFcn) of the nonlinear MPC controller.

The number of rows in parameters must match the number of rows in states and inputs.

If your controller prediction model has optional parameters, you must specify parameters.

Output Arguments

collapse all

Linear MPC controllers created for each nominal condition, returned as one of the following:

  • Single mpc object when N = 1.

  • Cell array of mpc objects of length N when N > 1. Each object corresponds to one nominal condition.

convertToMPC copies the following controller properties from nlmpcobj to the controllers in mpcobj:

  • Sample time

  • Prediction and control horizons

  • Tuning weights

  • Bounds on output variables, manipulated variables, and manipulated variable rates

  • Scale factors, names, and units for variables and disturbances

If nlmpcobj:

  • Has unmeasured disturbance channels, then the controllers in mpcobj have unity gains for their input and output disturbance models.

  • Does not have unmeasured disturbance channels, then the controllers in mpcobj have default output disturbance models.

Any state bounds in nlmpcobj are dropped during conversion.

Version History

Introduced in R2018b