Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

please correct the code..

1 visualizzazione (ultimi 30 giorni)
dav
dav il 18 Feb 2013
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

Risposte (1)

Youssef  Khmou
Youssef Khmou il 18 Feb 2013
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 Commenti
dav
dav il 18 Feb 2013
It still gives me the same error
Youssef  Khmou
Youssef Khmou il 18 Feb 2013
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 ?

Questa domanda è chiusa.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by