how to define the mpc object's plant as state space rather than transfer function. i tried to run this code but not working. % Define system matrices (Ad, Bd, Cd, Dd) for the quadruple tank system Ad = [-0.0173190, 0, 0.026219, 0; 0, -0.0113455, 0, 0.017708; 0, 0, -0.026219, 0; 0, 0, 0, -0.017708]; Bd = [0.0395, 0; 0, 0.03598; 0, 0.076375; 0.06378, 0]; Cd = [1, 0, 0, 0; 0, 1, 0, 0]; Dd = [0, 0; 0, 0]; % Define prediction and control horizons predictionHorizon = 10; % Adjust as needed controlHorizon = 3; % Adjust as needed % Define constraints (input and state constraints) inputConstraints = [-10, 10; -10, 10]; % Adjust as needed stateConstraints = [0, 40; 0, 40; 0, 40; 0, 40]; % Adjust as needed % Define cost function weights Q = eye(4); % State weight matrix (adjust as needed) R = eye(2); % Input weight matrix (adjust as needed) % Initial state x0 = [10; 10; 10; 10]; % Adjust the initial state as needed % MPC setup mpcobj = mpc(Ad, Bd, Cd, Dd, 'PredictionHorizon', predictionHorizon, 'ControlHorizon', controlHorizon);
Kshitij Singh answered .
2025-11-20
% Define system matrices (Ad, Bd, Cd, Dd) for the quadruple tank system Ad = [-0.0173190, 0, 0.026219, 0; 0, -0.0113455, 0, 0.017708; 0, 0, -0.026219, 0; 0, 0, 0, -0.017708]; Bd = [0.0395, 0; 0, 0.03598; 0, 0.076375; 0.06378, 0]; Cd = [1, 0, 0, 0; 0, 1, 0, 0]; Dd = [0, 0; 0, 0]; sys = ss(Ad, Bd, Cd, Dd) % <-- added this
sys =
A =
x1 x2 x3 x4
x1 -0.01732 0 0.02622 0
x2 0 -0.01135 0 0.01771
x3 0 0 -0.02622 0
x4 0 0 0 -0.01771
B =
u1 u2
x1 0.0395 0
x2 0 0.03598
x3 0 0.07637
x4 0.06378 0
C =
x1 x2 x3 x4
y1 1 0 0 0
y2 0 1 0 0
D =
u1 u2
y1 0 0
y2 0 0
Continuous-time state-space model.
% Define prediction and control horizons predictionHorizon = 10; % Adjust as needed controlHorizon = 3; % Adjust as needed % Define constraints (input and state constraints) inputConstraints = [-10, 10; -10, 10]; % Adjust as needed stateConstraints = [0, 40; 0, 40; 0, 40; 0, 40]; % Adjust as needed % Define cost function weights Q = eye(4); % State weight matrix (adjust as needed) R = eye(2); % Input weight matrix (adjust as needed) % Initial state x0 = [10; 10; 10; 10]; % Adjust the initial state as needed % MPC setup ts = 0.1; % <-- added this mpcobj = mpc(sys, ts, predictionHorizon, controlHorizon) % <-- fixed this
-->"Weights.ManipulatedVariables" is empty. Assuming default 0.00000.
-->"Weights.ManipulatedVariablesRate" is empty. Assuming default 0.10000.
-->"Weights.OutputVariables" is empty. Assuming default 1.00000.
MPC object (created on 19-Oct-2023 17:07:26):
---------------------------------------------
Sampling time: 0.1 (seconds)
Prediction Horizon: 10
Control Horizon: 3
Plant Model:
--------------
2 manipulated variable(s) -->| 4 states |
| |--> 2 measured output(s)
0 measured disturbance(s) -->| 2 inputs |
| |--> 0 unmeasured output(s)
0 unmeasured disturbance(s) -->| 2 outputs |
--------------
Disturbance and Noise Models:
Output disturbance model: default (type "getoutdist(mpcobj)" for details)
Measurement noise model: default (unity gain after scaling)
Weights:
ManipulatedVariables: [0 0]
ManipulatedVariablesRate: [0.1000 0.1000]
OutputVariables: [1 1]
ECR: 100000
State Estimation: Default Kalman Filter (type "getEstimator(mpcobj)" for details)
Unconstrained
Use built-in "active-set" QP solver with MaxIterations of 120.