?? rls.m
字號:
%**********帶遺忘因子的最小二乘估計算法(例2.1.2)**********
%**********a(t),b(t)為真實參數,cite為估值,lamda為遺忘因子*********
clear;
randn('seed',1);
e=sqrt(0.81)*randn(1,2020);
u=unifrnd(-1,1,1,2020);
a(1:1000)=-0.9;b(1:1000)=3;a(1001:2010)=0.9;b(1001:2010)=1;
y(1)=0;
lamda=0.99;
for t=1:2000
y(t+1)=a(t)*y(t)+b(t)*u(t)+e(t);
end
fai(:,1)=[0,0]'; cite(:,1)=[0;0];P=eye(2)*9999;
%********帶遺忘因子的自小二乘估計算法*********
for t=1:2000
fai(:,t+1)=[y(t),u(t)]';
cite(:,t+1)=cite(:,t)+P*fai(:,t+1)*(y(t+1)-fai(:,t+1)'*cite(:,t))/(lamda+fai(:,t+1)'*P*fai(:,t+1));
P=(P-(P*fai(:,t+1))*(P*fai(:,t+1))'/(lamda+fai(:,t+1)'*P*fai(:,t+1)))/lamda;
end
t=1:2000;
subplot(2,2,1)
title('參數a的收斂圖');
plot(t,a(t),t,cite(1,t),'r');
subplot(2,2,2)
title('參數b的收斂圖');
plot(t,b(t),t,cite(2,t),'r');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -