Algebraic state variables for nlmpc
24 views (last 30 days)
Show older comments
Hi all,
I am currently developing a nonlinear model predictive control that incorporates algebraic state variables (they are not equipped with derivative equation). Their equations would be in the form of 0 = Fx(k) + Gu(k). I need these state variables to complete the system. I am planning to utilize the Nonlinear Model Predictive Control Toolbox to control the system. However, I am not sure how to add this function in the model function without the derivative. Can anyone kindly explain to me how to incorporate these state variables to the nlmpc code?
Thank you in advance.
0 Comments
Accepted Answer
LeoAiE
on 2 Jul 2023
The Nonlinear Model Predictive Control Toolbox does support Differential-Algebraic Equation (DAE) systems, and you can incorporate algebraic equations into your model function.
function [dx, y] = myModel(t, x, u, varargin)
% x: Differential states
% u: Inputs
% dx: Derivatives of differential states
% Define your differential equations
dx(1,1) = ... % function of x, u and possibly t
% Define your output equations
y = ...
% Incorporate your algebraic equations
if nargin >= 4
% varargin{1} contains the algebraic states
xa = varargin{1};
% Define algebraic equations
dx(2,1) = 0 - F*x(1) - G*u; % 0 = Fx + Gu
end
end
And here is how to setup your nlmpc object with algebraic equations:
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);
% Define number of algebraic states
controller.Model.NumberOfVariables = nx + nu + nv;
% Define Jacobian of the model with respect to algebraic states
controller.Model.Jacobian.OutputVariables = @(t, x, u, varargin) ...
[0, 0, -G]; % Assuming G is constant w.r.t x, u, and xa
In this way, the nonlinear MPC controller knows that it must solve the algebraic equation for xa at each control interval.
Note that providing the Jacobian can significantly improve the controller's performance. The Jacobian function should return the partial derivatives of the output equations with respect to all state, input, and algebraic variables. Please adjust according to your specific model and function F. Also, ensure the dimensions match your model size.
Remember to use your specific model details in place of this simplified example. Make sure to test this on a smaller scale or with test data to ensure functionality before implementing it into your system. Finally, this is just a starting point. You may need to adjust this code to fit your needs, such as defining prediction and control horizons, constraints, weights, and other specifics of your system and control strategy.
Hope this helps!
8 Comments
Lars
on 2 Jan 2024
Hello,
is it as well possible to define in the state function a system of DAE for the states itself? Something like the following equations:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1580986/image.png)
This system can be solved as specified e.g. as described here: (https://de.mathworks.com/help/symbolic/solve-differential-algebraic-equations.html) But I haven't seen any option to specify a DAE system within the state function for a NLMPC model. Is there any option?
Thanks in advance.
More Answers (0)
See Also
Categories
Find more on Nonlinear MPC Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!