📄 mpc1.m
字号:
% A simple matlab program to illustrate MPC
% EE6225, KVL, 5 March 2007
clear all
% define the plant and set-point
az = [1 -0.7]; bz = [2];
w = 1; %set-point
% storage for simulation
yplant=0; uplant=0; ydata=[]; udata=[]; wdata=[]; tdata=[];
for k=1:10
%measure the current plant output
yk = yplant;
% calculate the MPC control
uk = (w - 0.49*yk)/(1.4+2);
% store the data for plotting later
tdata = [tdata; k-1]; wdata = [wdata; w];
ydata = [ydata; yk]; udata = [udata; uk];
% apply the control to the plant
uplant = uk;
% simulate the plant
yp_new = -az(2)*yplant + bz*uplant;
yplant = yp_new;
end
subplot(211),plot(tdata,wdata,tdata,ydata),ylabel('Output'),xlabel('Samples')
subplot(212),stairs(tdata,udata),ylabel('Control'),xlabel('Samples')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -