我有以下代码 *. 在此我将变量“epsf1”更改为先前的值“epsf1 = eps[ii,1]-c1*epsf1”。我打印它的值,它是 0。但它应该是完全不同的东西。我找不到它发生的原因,我无法用同样的问题编写更短的代码。看起来“eps[ii]”中的值没有用于“epsf1 = eps[ii,1]-c1*epsf1;” 陈述。
*:
delka_experimentu = 1000;
lambda = 1;
Q = diag(3);
e = rnorm(delka_experimentu);
u = rnorm(delka_experimentu);#rep(10,delka_experimentu)
y = rep(0,delka_experimentu);
y[1] = e[1];
for(ii in c(2:delka_experimentu)){
y[ii] = 0.5*y[ii-1]+0.3*u[ii-1]+e[ii]-0.2*e[ii];
}
Res = matrix(0,delka_experimentu,6);
P = 1000*diag(3);
R1 = 0.1*diag(3);
K = matrix(0,3,1);
eps = matrix(0,delka_experimentu,1)
epsf1 = y[1];
print(c(epsf1))
epsf2 = 0;
ef3 = 0;
yf1 = y[1];
yf2 = 0;
yf3 = 0;
uf1 = u[1];
uf2 = 0;
uf3 = 0;
eps[1,1] = y[1];
epst1 = 0;
pomocna1 = 0;
pomocna2 = 0;
theta = matrix(0,3,1);
for(ii in 2:30){ #delka_experimentu
a1 = theta[1];
b1 = theta[2];
c1 = theta[3];
pomocna1 = epsf1;
epsf1 = eps[ii,1]-c1*epsf1;
epsf2 = pomocna1;
print(c(epsf1))
pomocna1 = yf1;
yf1 = y[ii]-c1*yf1;
yf2 = pomocna1;
pomocna1 = uf1;
uf1 = u[ii]-c1*uf1;
uf2 = pomocna1;
eps[ii,1] = y[ii]+a1*y[ii-1]-b1*u[ii-1]-c1*eps[ii-1]
#if(eps[ii]*eps[ii]>100){paste("problem",ii)}
psi = matrix(c(yf2,uf2,epsf2),3,1);
b = t(psi)%*%P%*%psi;
P = (P - P%*%psi%*%solve(1+b[1,1])%*%t(psi)%*%P)/lambda #lambda*solve(Q)
K = P%*%psi%*%solve(1+b[1,1]); #lambda*solve(Q)
theta = theta + K%*%eps[ii];
Res[ii,] = theta;
}
plot(c(0,delka_experimentu),c(min(Res,-0.5),max(Res,1)),col="white")
lines(Res[,1],col="red")
#lines(Res[,2],col="red",type=o)
lines(Res[,3],col="blue")
#lines(Res[,4],col="blue")
lines(Res[,5])
#lines(Res[,6])
lines(c(0,delka_experimentu),c(-0.5,-0.5),col="red")
lines(c(0,delka_experimentu),c(0.3,0.3),col="blue")
lines(c(0,delka_experimentu),c(-0.2,-0.2))