mpc1.m

来自「3个关于预测控制的matlab函数」· M 代码 · 共 24 行

M
24
字号
% 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 + =
减小字号Ctrl + -
显示快捷键?