Model predictive control plots

2 次查看(过去 30 天)
I am working with model predictive control. How to plot two mpc controllers output in single plot. If I create two mpc controllers by using MPCOBJ command then I wanted to plot two outputs in same plot. otherwise I apply a single mpc controller to two different plants here also i wanted to plot two responses in single plot.

采纳的回答

atharva
atharva 2023-12-19
Hey K Kalanithi,
I understand that you want to know how to plot 2 mpc controllers output in a single plot
To plot the outputs of two MPC controllers in a single plot, you can use the sim function to simulate the controllers and then plot the results. Here's an example:
% Create two MPC controllers
mpc1 = mpc(sys1, Ts);
mpc2 = mpc(sys2, Ts);
% Simulate the controllers
T = 10; % Simulation time
r = ones(T, 1); % Reference signal
[y1, ~, u1] = sim(mpc1, T, r);
[y2, ~, u2] = sim(mpc2, T, r);
% Plot the outputs
t = (0:T-1)*Ts; % Time vector
figure;
plot(t, y1, 'b', t, y2, 'r');
xlabel('Time');
ylabel('Output');
legend('MPC 1', 'MPC 2');
In this example, sys1 and sys2 are the plant models, Ts is the sampling time, and T is the simulation time. The sim function is used to simulate the controllers and obtain the outputs y1 and y2. These outputs are then plotted in a single plot using the plot function.
You can go through the MathWorks documentation mentioned below for a better understanding
I hope this helps!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Model Predictive Control Toolbox 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by