clc
clear

%

%24h 基于混合变量
load('C:\tongbu\BaiduSyncdisk\02PHD\03study\03实验\第一篇论文实验\1.第一次48h\matlab\y1.mat')
load('C:\tongbu\BaiduSyncdisk\02PHD\03study\03实验\第一篇论文实验\1.第一次48h\matlab\u1.mat')
load('C:\tongbu\BaiduSyncdisk\02PHD\03study\03实验\第一篇论文实验\1.第一次48h\matlab\u2.mat')
load('C:\tongbu\BaiduSyncdisk\02PHD\03study\03实验\第一篇论文实验\1.第一次48h\matlab\y2.mat')
load('C:\tongbu\BaiduSyncdisk\02PHD\03study\03实验\第一篇论文实验\1.第一次48h\matlab\z5.mat')
Ts=5;%采样时间5min
ze1=iddata(y1,u1,Ts);%训练
zv1=iddata(y1,u1,Ts);%验证

V1= arxstruc(zv1(:,:,1),ze1(:,:,1),struc(1:4,1:4,1:4));
nn1 = selstruc(V1,'MDL');
% %第二种输入-输出组合的模型顺序
V2= arxstruc(zv1(:,:,2),ze1(:,:,2),struc(1:4,1:4,1:4));
nn2 = selstruc(V2,'MDL');
% 第3种输入-输出组合的模型顺序
V3= arxstruc(zv1(:,:,3),ze1(:,:,3),struc(1:4,1:4,1:4));
nn3= selstruc(V3,'MDL');

M = arx(ze1,'na',4,'nb',[ 1 4 4 ],'nk',[2 3 1 ]);
compare(ze1,M)%将ARX模型的输出与测量输出进行比较。
present(M);

%

%用1数据模型预测2数据的热伸长
clc
clear

%

load('C:\tongbu\BaiduSyncdisk\02PHD\03study\03实验\第一篇论文实验\1.第一次48h\matlab\x5.mat')
load('C:\tongbu\BaiduSyncdisk\02PHD\03study\03实验\第一篇论文实验\1.第一次48h\matlab\y1.mat')
load('C:\tongbu\BaiduSyncdisk\02PHD\03study\03实验\第一篇论文实验\1.第一次48h\matlab\u1.mat')
load('C:\tongbu\BaiduSyncdisk\02PHD\03study\03实验\第一篇论文实验\1.第一次48h\matlab\u2.mat')
load('C:\tongbu\BaiduSyncdisk\02PHD\03study\03实验\第一篇论文实验\1.第一次48h\matlab\y2.mat')
load('C:\tongbu\BaiduSyncdisk\02PHD\03study\03实验\第一篇论文实验\1.第一次48h\matlab\z5.mat')
x1=u2(:,1)
x2=u2(:,2)
x3=u2(:,3)
E=y2(1:4,:)
Et=y2(1:4,:)

%

%输出三个模型对比图
for  t=5:281
    E(t)=1.547*E(t-1)-0.3602*E(t-2)-0.3331*E(t-3)+0.1285*E(t-4)-0.02217*x1(t-2)+0.4526*x2(t-3)-0.3914*x2(t-4)-0.2327*x3(t-1)+0.1741*x3(t-2);
    Et(t)=1.523*Et(t-1)-0.341*Et(t-2)-0.3603*Et(t-3)+0.152*Et(t-4)-0.004719*x1(t-2)+0.1866*x2(t-3)-0.0988*x2(t-4)+0.6532*x5(t-1)-0.6769*x5(t-2);
end
for  t=1:281
    E_MDL(t)=30.4267+ 1.7547.* x1(t) -1.55.* x2(t) + 5.1559.* x5(t)
end
E_MDL=E_MDL';
figure(1)
plot(z5,y2,z5,E,':',z5,Et,':.',z5,E_MDL,'--','linewidth',1.5)
ylabel('Error[μm]','FontSize',10)
xlabel('Time[min]','FontSize',10)
legend('Measured Values','MV-ARX Model Predictions','TV-ARX Model Predictions','MLR Model Predictions')

%

E_MDL=E_MDL';

%


%输出三个模型残差图
y5=abs(E-y2);
y6=abs(Et-y2);
y7=abs(E_MDL-y2);
figure(2)
plot(z5,y5,z5,y6,':',z5,y7,'--','linewidth',1.5)
ylabel('Residual Error[μm]','FontSize',10)
xlabel('Time[min]','FontSize',10)
legend('MV-ARX Model','TV-ARX Model','MLR Model')

%

R1 = rmse(E,y2);
R2 = rmse(Et,y2);
R3 = rmse(E_MDL,y2);
mae1 = mean(abs(E- y2));
mae2 = mean(abs(Et- y2));
mae3 = mean(abs(E_MDL- y2));

%

ymax=max(y2);
ymin=min(y2);
yc=abs(ymax- ymin);
fit1=(1-R1/yc)*100;
fit2=(1-R2/yc)*100;
fit3=(1-R3/yc)*100;