Clear Filters
Clear Filters

Model predictive control plots

2 views (last 30 days)
K Kalanithi
K Kalanithi on 19 Dec 2023
Commented: K Kalanithi on 24 Dec 2023
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.

Accepted Answer

atharva
atharva on 19 Dec 2023
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!
  1 Comment
K Kalanithi
K Kalanithi on 24 Dec 2023
Thank you for your answer. it is fruitful for my work.

Sign in to comment.

More Answers (0)

Categories

Find more on Model Predictive Control Toolbox in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!