www.pudn.com > kicILC-control.rar > kicr_control.asv, change:2013-06-21,size:2896b

```%global uk duk
%%产生输入数据
clear;
%pr=idinput(21,'prbs',[0 1],[0 2]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1
%该大段程序的目的就是仿真产生非高斯分布的实验数据（控制输入变量），李赣平老师给的，程序非常累赘。其实就几句话可以解决的，本来来想精简下，后来还是算了，
for j=1:60
t=(0:0.05:1)';
ut=[];
ut=[ut,i];
for i=1:length(t)
ut(i,1)=t(i,1);
if i<=12,
ut(i,2)=0.97;
else
ut(i,2)=0.92;
end
us(j,i)=ut(i,2)+0.043*(-1+2*rand(1,1));

%us(j,i)=ut(i,2)+0.043*(-1+pr(i));
%us(j,i)=ut(i,2)+0.058*rand(1,1);
%uk(i,1)=ut(i,2);
uk(i,1)=us(1,i);

duk(i,1)=0;

ut(i,2)=us(j,i);
end
%us(j,:)=ut(:,2)+normrnd(0,0.3,21,1);
%ut(:,2)=us(j,:);
u=us(:,1:21);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1
opts=simset('OutputVariables','xy');
[t1,x,y]=sim('nzz1.mdl',[0:0.05:1],opts,ut);
x1(j,1)=x(21,1);
x2(j,1)=x(21,2);
end
X=u(1:30,:);%训练集
Y1=x2(1:30);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1
%将实验数据依次依照我设计的函数格式
X_train=X.';
Y_train=Y1.';
X_test=u(31:end,:).';%训练集
Y_test=x1(31:end,:).';
%
[MSE_validate,A,rbf_var ] = offlinetrain_kicr(X_train,Y_train,X_test,Y_test);

[X_train,mean_X_train,std_X_train]=zscore(X_train,0,2);
[Y_train,mean_Y_train,std_Y_train]=zscore(Y_train,0,2);
[X_test,mean_X_test,std_X_test]=zscore(X_test,0,2);
[Y_test,mean_Y_test,std_Y_test]=zscore(Y_test,0,2);

%%迭代学习控制仿真
G=zeros(21,1);
v=0.01*ones(21,1);
R=diag(v,0);
Q=[1000];
Yd=[0.606]';

for i=1:300
Yd1(i)=Yd;

uin=[t,uk];
if i<=300,
[t_1,x_1,y_1]=sim('nzz1.mdl',[0:0.05:1],opts,uin);

else
[t_1,x_1,y_1]=sim('nzz2.mdl',[0:0.05:1],opts,uin);

end
Ye(1,i)=x_1(21,2)';
Ek(1,i)=Yd-x_1(21,2)';%+0.05*randn(2,1);
Index(i)=norm(Ek(1,i),2);%Ek(:,i)'*Q*Ek(:,i);

uk=(uk-mean_X_train)./std_X_train;
for j=1:30
G(:,1)=G(:,1)-std_Y_train*2*A(1,j)*(uk-X_train(:,j))/rbf_var*exp(-(norm(uk-X_train(:,j)))^2/rbf_var);
%G(:,2)=G(:,2)-std_Y(2)*2*A(2,j)*(uk-u1(:,j))/rbf_var*exp(-(norm(uk-u1(:,j)))^2/rbf_var);
%G1(:,1)=G1(:,1)+(d*alpha2(j)*u(j,:))'*(u(j,:)*uk1+1)^(d-1);

end

duk=((G*Q*G'+R))\(G*Q*(Yd-Ye(1,i)));
uk=uk+duk;
uk=uk.*std_X_train+mean_X_train;

end
figure(1)
plot(1:10:300,Index(1:10:300),'o');
hold on;
plot(1:10:300,Index(1:10:300),'-');
hold on;
xlabel(' Iteration Number','FontSize',11);
ylabel('Sum of Squared Control Errors','FontSize',11);
hold off;
figure(3)
plot(1:10:300,Ye(1:10:300),'o');
hold on;
plot(1:10:300,Ye(1:10:300),'-');
hold on;
plot(1:10:300,Yd1(1:10:300),'--');
xlabel(' Iteration Number','FontSize',11);
ylabel('X2(tf)','FontSize',11);
hold off;
```