Skip to content

Instantly share code, notes, and snippets.

@aligo
Forked from anonymous/gist:3115954
Created July 15, 2012 08:50
Show Gist options
  • Save aligo/3115958 to your computer and use it in GitHub Desktop.
Save aligo/3115958 to your computer and use it in GitHub Desktop.
x=[1:1006];
w=1.2;
x=sin(w.*x);
q(1)=0;
q(2)=0;
for i=3:1005,
q(i)=1.5*q(i-1)-0.7*q(i-2)+x(i-1)+0.5*x(i-2)+randn(1,1);
end
for i=1:1000,
q(i)=q(i+2);
end
%初始化
m=3;
k=0.8;
ee=0;
for i=1:m,
for j=1:m,
a(i,j)=x(i+j);
end
end
[u,s,v]=svd(a);
for i=1:m,
b(i)=q(i);
end
b=u'*b';
%迭代
for t=2:1000,
bb=0;
r=rank(v)
%a的迭代
s1(1:r,1:m)=s(1:r,1:m);
u1(1:r,1:m)=u(1:r,1:m);
a=s1.*v;
a=0.8.*a;
for j=1:m,
a(r+1,j)=x(t-1+j);
end
[u,s,v]=svd(a);
%b的迭代
b=0.8.*b;
b(r+1)=q(t);
bb(1:r+1)=b(1:r+1);
bb=u'*bb';
%系数
for i=1:r,
w(i)=bb(i)./s(i,i);
end
%error
ww=w';
e=bb-a*ww;
ee=normest(e);
hold on
axis([1 1000 -10 10]);
plot(t,e);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment