Only algebraic system equations in Model Predictive Control Toolbox?

16 views (last 30 days)
My goal ist to use Model Predictive Control (MPC) for high-level planning. Instead of having differential equations I want to use only algebraic equations in the state function.
The equations would be in the form . Is there a way to define the MPC state functions as such?
Preferably I would use the nonlinear version of MPC.
Thank you very much.
Best regards,
Martin
  2 Comments
Martin Rohrmüller
Martin Rohrmüller on 2 Aug 2024
Dear Divyanshu,
thank you for your answer and the link. I have checked out the thread. It really addresses the problem, however I could not get along with their answers:
1. The accepted answer suggests this code, which is throwing an error:
nx = 1; % Number of differential states
nu = 1; % Number of inputs
ny = 1; % Number of outputs
nv = 1; % Number of algebraic states
Ts = 0.1; % Sample time
model = @myModel; % Model function
controller = nlmpc(nx, ny, 'Model', model, 'Ts', Ts, 'MV', 1);
Error using nlmpc (line 894)
Input channel must be one of the following types: 'MV' (manipulated variable), 'MD' (measured disturbance), or 'UD' (unmeasured disturbance).
Additionally, the controller object does not seem to have this variable:
controller.Model.NumberOfVariables
Thus, I did not find a way to specify the additional algebraic states.
2. The creator of the thread implements it in a different way (example code in the comments). But from my understanding the algebraic states are never computed there.
To summarize, it would be helpful to have an example that shows the correct setup of the nlmpc objects (I am using R2024a currently).
Best,
Martin

Sign in to comment.

Answers (1)

SAI SRUJAN
SAI SRUJAN on 13 Aug 2024
Hi Martin,
I understand that you are facing an issue with finding an example that shows the correct setup of the 'nlmpc' objects.
Refer to the following code sample to proceed further,
function dx = myModel(x, u)
% x: differential states
% u: inputs
% Define the algebraic equation f(u, x)
f = @(u, x) x^2 + u; % Example algebraic function
% Compute the state update based on x = u - f(u, x)
dx = u - f(u, x);
end
% Number of states, inputs, and outputs
nx = 1; % Number of differential states
nu = 1; % Number of inputs
ny = 1; % Number of outputs
Ts = 0.1; % Sample time
% Create nlmpc object
nlobj = nlmpc(nx, ny, nu);
nlobj.Ts = Ts;
% Specify the model function
nlobj.Model.StateFcn = @myModel;
% Define the output function (for simplicity, let's assume output is x)
nlobj.Model.OutputFcn = @(x, u) x;
% Define constraints and weights (optional)
nlobj.Weights.ManipulatedVariables = 0.1;
nlobj.Weights.ManipulatedVariablesRate = 0.1;
nlobj.Weights.OutputVariables = 1;
% Validate the model
validateFcns(nlobj, rand(nx,1), rand(nu,1));
Model.StateFcn is OK. Model.OutputFcn is OK. Analysis of user-provided model, cost, and constraint functions complete.
For a comprehensive understanding of the "nlmpc" function in MATLAB, please refer to the following documentation.
I hope this helps!

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!