Info
此问题已关闭。 请重新打开它进行编辑或回答。
please correct the code..
1 次查看(过去 30 天)
显示 更早的评论
Can someone please correct the error in the following code:
a0 = 0.05; a1 = 0.1; b1 = 0.85;
nu = randn(2300,1);
epsi = zeros(2300,1);
h = zeros(2300,1);
for i=2: 2300
h(i) = a0 + a1 * epsi(i-1)^2 + b1 * h(i-1) ;
epsi(i) = nu(i) * sqrt(h(i));
end
yt = zeros(2300,1);
for i=1: 2300
yt(i) = epsi(i)*epsi(i);
end
order = 5;
m = arx(yt, order);
r = resid([yt(1:order);yt], m);
r = r(order+1:end);
yt2 = zeros(2300,1);
for i=1: 2300
yt2(i) = yt(i)- r(i);
end
yt2(1:1300) = [];
yt(1:1299)=[];
yt(1001:1001)=[];
r(1:1299)=[];
r(1001:1001)=[];
x = [yt,r];
a = eye(2);
b = zeros(2,1);
opts = optimset('lsqlin');
opts.LargeScale = 'off';
opts.Display = 'none';
coef = lsqlin(x,yt2,-a,-b);
thanks
1 个评论
回答(1 个)
Youssef Khmou
2013-2-18
The code is correct, but i made a small change :
a0 = 0.05;
a1 = 0.1;
b1 = 0.85;
nu = randn(2300,1);
epsi = zeros(2300,1);
h = zeros(2300,1);
for i=2: 2300
h(i) = a0 + a1 * epsi(i-1)^2 + b1 * h(i-1) ;
epsi(i) = nu(i) * sqrt(h(i));
end
yt = epsi.^2; % no need to use loop to ^2 .
%for i=1:2300
% yt(i) = epsi(i)*epsi(i);
%end
order = 5;
m = arx(yt,order);
r = resid([yt(1:order);yt], m);
r = r(order+1:end);
yt2 = zeros(2300,1);
for i=1:2300
yt2(i) = yt(i)- r(i);
end
yt2(1:1300) = [];
yt(1:1299)=[];
yt(1001:1001)=[];
r(1:1299)=[];
r(1001:1001)=[];
x = [yt,r];
a = eye(2);
b = zeros(2,1);
opts = optimset('lsqlin');
opts.LargeScale = 'off';
opts.Display = 'none';
coef = lsqlin(x,yt2,-a,-b);
2 个评论
Youssef Khmou
2013-2-18
hi, i just tried it again, it works, it plot a figure of the "correlation function of the residuals", !!! what kind of error? can you copy and paste the error output ?
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!