一,预测模型:
此处的A,B,C为n*n阶矩阵,n取决与于被控对象y的个数
二,E,F,G,H丢番图递推公式求解:
单变量中e,f,g为一个数,此次e,f,g表示为n*n阶的矩阵,n为输入变量个数,每个e,f,g都包含了所有的被控对象的信息。
递推公式与单变量的完全类似,此次不再叙述。
三,跟踪轨迹:
四,求解控制律:
文章来源:https://www.toymoban.com/news/detail-762576.html
这里为什么要重新组合,是因为y1和PT要和的matrix_d被控对象y的位置对应上。文章来源地址https://www.toymoban.com/news/detail-762576.html
五,仿真程序:
clear all
clc
close all
%---------------------------------------------------------%
%---GPC算法 MIMO---%
% 参考文献 吕剑虹 《多变量系统的广义预测控制及其应用》%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% part 1 参数 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%仿真时间或者步长(实控的时候 不需要了)
simulationiter1 = 100;
simulationiter2 = 200;
simulationiter3 = 350;
% 实际系统 dim_m输入dim_m输出系统(针对与方阵系统)
% a_real = {[1 0;0 1],[0.5 0;0 0.5],[0.2 0 ;0 0.2]};%A(q-1) of process
% b_real = {[0.5 0;0 0.5]};%B(q-1) of process
a_real={[1 0;0 1],[-1.6608 0;0 -2.4063],[0.7589 0 ;0 1.9283],[-0.056 0 ;0 -0.5147]};%A(q-1) of process
b_real={[0.3363 0.0116;-0.2937 0.027],[-0.2640 0.0221;0.4230 0.0311],...
[-0.3363 0.0095;-0.1251 -0.019],[0.2640 -0.0011;-0.0204 -0.0230]};%B(q-1) of process
k_real=1;%time delay of process
dim_m = length(cell2mat(a_real(1,1)));%cell2mat将云胞数组转化为数值数组
%实际系统包含噪声
for i=1:simulationiter3
for j = 1:dim_m
u(j,i)=0;%init U
noise(j,i)=0*randn()/10;%init random noise
y_real(j,i) = noise(j,i);%init real y
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%模型参数
a_model = a_real;
b_model = b_real;
k_model = k_real;
% a_model={[1 0;0 1],[-1.6608 0;0 -2.4063],[0.7589 0 ;0 1.9283],[-0.056 0 ;0 -0.5147]};%A(q-1) of model
% b_model={[0.3363 0.0116;-0.2937 0.027],[-0.2640 0.0221;0.4230 0.0311],...
% [-0.3363 0.0095;-0.1251 -0.019],[0.2640 -0.0011;-0.0204 -0.0230]};%B(q-1) of model
% k_model=1;%time delay of model
na=length(a_model)-1;
nb=length(b_model)-1;
%GPC配置参数%(实控的时候 需要)
GPC_p=6;%predict horizon
GPC_m=6;%control horizon
lambda=[1 10];
GPC_lambda=diag(lambda);%control weight控制权重
%生成正方,diag(v,k)V是对角矩阵,K是该对角矩阵放的位置
alfa=[0.5 0];
GPC_alfa=diag(alfa);%soften parameter 柔化因子
GPC_beta=0;%step scale 阶梯因子 可不用
DMC_sp1 = [5 5]; %设定值
DMC_sp2 = [15 5]; %设定值
DMC_sp3 = [25 5]; %设定值
for i=1:simulationiter1
y_set(:,i)=DMC_sp1;
end%init setpoint of y
for i=(simulationiter1+1):simulationiter2
y_set(:,i)=DMC_sp2;
end%init setpoint of y
for i=(simulationiter2+1):simulationiter3
y_set(:,i)=DMC_sp3;
end%init setpoint of y
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% part 2 init polynomials %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
matrix_e=cell(k_model+GPC_p-1,1); % E 丢番图方程
matrix_f=cell(na+1,k_model+GPC_p-1); %F 丢番图方程
matrixg_whole=cell(k_model+GPC_p-1,nb+k_model+GPC_p-1); % G= E*B 丢番图方程
g_single = cell(1,k_model+GPC_p-1);
g_part = cell(k_model+GPC_p-1,k_model+GPC_p-1);
g_part2 = cell(GPC_p,GPC_m);
matrix_e(:,:) = {zeros(dim_m)};
matrix_f(:,:) = {zeros(dim_m)};
matrixg_whole(:,:) = {zeros(dim_m)};
g_single(:,:) = {zeros(dim_m)};
g_part(:,:) = {zeros(dim_m)};
g_part2(:,:) = {zeros(dim_m)};
%计算F 丢番图方程
matrix_f{1,1}=eye(dim_m)-a_model{1,2};
for i=1:1:na-1
matrix_f{i+1,1}=a_model{1,i+1}-a_model{1,i+2};
end
matrix_f{na+1,1}=a_model{1,na+1};
%计算E 丢番图方程
matrix_e{1,1}=eye(dim_m);
for j=2:1:k_model+GPC_p-1
matrix_e{j,1}=matrix_f{1,j-1};
matrix_f{1,j}=matrix_f{2,j-1}-matrix_e{j,1}*(a_model{1,2}-eye(dim_m));
for i=1:1:na-1
matrix_f{i+1,j}=matrix_f{i+2,j-1}-matrix_e{j,1}*(a_model{1,i+2}-a_model{1,i+1});
end
matrix_f{na+1,j}=matrix_e{j,1}*a_model{1,na+1};
end%init e,f
%计算G= E*B 丢番图方程
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:nb+1
matrixg_whole{1,i}=b_model{1,i};
end
for j=2:k_model+GPC_p-1
for i=1:nb+j-1+1
if i<=j-1
matrixg_whole{j,i}=matrixg_whole{j-1,i};
elseif i<=nb+j-1
matrixg_whole{j,i}=matrixg_whole{j-1,i} +matrix_e{j,1}*b_model{1,i-j+1};
elseif i==nb+j
matrixg_whole{j,i}=matrix_e{j,1}*b_model{1,nb+1};
end
end
end%inint g
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:GPC_p
g_single{1,i}=matrixg_whole{k_model+GPC_p-1,i};
end
for j=1:GPC_p
for i=1:j
g_part{j,i}=g_single{1,j-i+1};
end
end
for j=1:GPC_p
for i=1:GPC_m
g_part2{j,i}=g_part{j,i};
end
end%init g_part for teh use of control of different forms
% 离线计算D矩阵
tempeye = cell(GPC_m,GPC_m);
tempeye(:,:) = {zeros(dim_m)};
for i = 1:GPC_m
tempeye(i,i) = {GPC_lambda};%yelei
end
temp = inv(cell2mat((g_part2))'*cell2mat((g_part2))+cell2mat(tempeye))*cell2mat((g_part2))';%yelei
matrix_d = temp(1:dim_m,:);
X=cell2mat((g_part2))
% matrix_d = [0.0456 0 0.0331 0 0.0329 0 0.0310 0 0.03 0 0.0295 0;...
% 0 0.0456 0 0.0331 0 0.0329 0 0.0310 0 0.03 0 0.0295]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% part 3 normoal control %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
maxn=max(k_real+nb+1,na+1);
for t=maxn:simulationiter3
y_real(1:dim_m,t)=noise(1:dim_m,t);
for i=1:nb+1
y_real(1:dim_m,t)=y_real(1:dim_m,t)+b_real{1,i}*u(1:dim_m,t-k_real-i+1);
end
for i=1:na
y_real(1:dim_m,t)=y_real(1:dim_m,t)-a_real{1,i+1}*y_real(1:dim_m,t-i);
end%sampleing
y_show = y_real(1:dim_m,t)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=0:GPC_p-1
y1(i+1,1:dim_m)=0;
for l=1:na+1
y1(i+1,1:dim_m)=y1(i+1,1:dim_m)'+matrix_f{l,i+k_model}*y_real(1:dim_m,t-l+1);
end
for l=i+2:nb+k_model+i
y1(i+1,1:dim_m)=y1(i+1,1:dim_m)'+matrixg_whole{k_model+i,l}*(u(1:dim_m,t+i+1-l)-u(1:dim_m,t+i-l));
end
end%init y1
[hang,lie] = size(y1);
y1MIMO = [];
for i=1:hang
y1MIMO = [y1MIMO,y1(i,:)];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
w_start=0;
if k_model==1
w_start=y_real(1:dim_m,t);
else
for l=1:na+1
w_start= w_start+matrix_f{l,k_model-1}*y_real(1:dim_m,t-l+1);
end
for l=1:nb+k_model-1
w_start= w_start+matrixg_whole{k_model-1,l}*(u(1:dim_m,t-l)-u(1:dim_m,t-l-1));
end%init w_start
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
w(1:dim_m,1)=GPC_alfa*w_start+(eye(dim_m)-GPC_alfa)*y_set(1:dim_m,t);%yelei
for i=1:GPC_p-1
w(1:dim_m,i+1)=GPC_alfa*w(1:dim_m,i)+(eye(dim_m)-GPC_alfa)*y_set(1:dim_m,t);%yelei
end%init w
[hang,lie] = size(w);
wMIMO = [];
for i=1:lie
wMIMO = [wMIMO;w(:,i)];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
u_delta = matrix_d *(wMIMO-y1MIMO')
u(1:dim_m,t)=u(1:dim_m,t-1)+u_delta;%get u if you choose normal gpc
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% part 4 plot the result %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% figure(1),subplot(2,1,1),plot(y_set(1,:),'y');hold on;
% plot(y_real(1,:),'r');hold on;
% plot(y_real(2,:),'b');hold on;
% legend('set','y1','y2');hold on;
% grid on
% % axis([0,simulationiter3-10,-inf,inf])
% subplot(2,1,2),plot(u(1,:),'r');hold on;
% plot(u(2,:),'b');legend('u1','u2');hold on;
% % axis([0,simulationiter3-10,-inf,inf])
% grid on
figure(1),subplot(2,1,1),plot(y_set(1,:),'r');hold on;
plot(y_real(1,:),'b');legend('设定值','输出值');hold on;
% axis([0,simulationiter3-10,-inf,inf])
subplot(2,1,2),plot(u(1,:),'g');hold on;
plot(u(2,:),'b');legend('u1','u2');hold on;
% axis([0,simulationiter3-10,-inf,inf])
figure(2),subplot(2,1,1),plot(y_set(2,:),'r');hold on;
plot(y_real(2,:),'b');legend('设定值','输出值');hold on;
% axis([0,simulationiter3-10,-inf,inf])
subplot(2,1,2),plot(u(1,:),'g');hold on;
plot(u(2,:),'b');legend('u1','u2');hold on;
% axis([0,simulationiter3-10,-inf,inf])
到了这里,关于多输入多输出广义预测控制(MIMO_GPC)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!