文档详情

MPC仿真程序MATLAB.pdf

发布:2019-08-08约1.33千字共3页下载文档
文本预览下载声明
clear clc A=[0.8 0;0.8 1]; B=[0.1;0.1]; C=[0 1]; D=0; P=10; M=4; MAX=15; MIN=-MAX; N=50; % Performance wights Q=eye(P); R=0.01*eye(M); %Q1=eye(P*ncr); R1=ones(P,1); % Predefined reference Re=zeros(50,1); Re(1:15)=2; Re(16:30)=5; Re(31:40)=2; [nbr,nbc]=size(B); [nar,nac]=size(A); [ncr,ncc]=size(C); %x0=[1;1]; %u(0)=0; y=zeros(N,1); u=zeros(N,1); %% S=zeros(P*ncr,M*nbc); for i=0:P-1 for j=0:M-1 if i=j S(i*ncr+1:(i+1)*ncr,j*nbc+1:(j+1)*nbc)=C*A^(i-j)*B; end end end %% T=zeros(P*ncr,nac); for i=0:P-1 T(i*ncr+1:(i+1)*ncr,:)=C*A^(i+1); end S_S=S*S; S_T=S*T; S_R1=S*R1; x0=[0;0]; u0=0; % Uk=zeros(N,1); % H=2*(R1+S*Q1*S); % f1=T*x0-Re; % Y=2*(Q+T*Q1*T); % uk=u0; for k=1:N A_co=[eye(M);-eye(M)]; b_co=[MAX*ones(4,1);-1*MIN*ones(4,1)]; U=quadprog(2*(S_S+R),-2*S*(R1*Re(k)-T*x0),A_co,b_co); u(k)=U(1); if k==1 Uk(k)=u(k); else Uk(k)=Uk(k-1)+u(k); end y(k)=C*x0+D*u(k); x0=A*x0+B*u(k) ; end %figure(1) subplot(2,1,1) hold on plot(Re,r) plot(y) title(output y) %figure(2) text(40,5,Red:set) text(40,4,Blue:y) subplot(2,1,2) hold on plot(u,r) %title(input delta u) %figure(3) plot(Uk) title(input u) text(40,17,Red:delta u) text(40,12,Blue:u)
显示全部
相似文档