Model predictive control plots
4 次查看(过去 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.
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Controller Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!