www.pudn.com > mpc.rar > mpc.m, change:2014-03-02,size:793b


% 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')

2018无需申请注册送58体验金