原始对象 1 不能用作迭代器

Raw object 1 cannot be used as an iterator

我已经改写如下,

NN = 2000;
mu = 0;
sigma = 10;
task3a = Table[Random[NormalDistribution[mu,sigma]], {NN}];
ListPlot[task3a, AxesLabel->{" No.obs.", "value of the obs"}, 
PlotLabel -> " Normal Distribution"];

a= 0.6; 
b =-0.45; 

task4a = Table [0, {NN}] ; 
task4a[[1]] = task3a[[1]]; 
task4a[[2]] = a*task4a[[1]] +task3a[[2]]; 
For [i = 3, i <= NN, i++, 
    task4a[[i]] = a*task4a[[i -1]] 
                + b*task4a[[i -2]] 
                + task3a[[i]];
] 
ListPlot[task4a, AxesLabel -> {"No.obs.", "value of the obs"}, PlotLabel-> "Autoregression process for norm.dist. white noise"];

(**************************************************)
avg = (1/NN) * Sum[task4a[[i]], {1, NN}]; 

task5a = Table[0, {33}] ; 

For [k = 0, k <= 32, k++, 
  task5a[[k + 1]] = (1/(NN-k)) * 
  Sum[(task4a[[i]] -avg)*(task4a[[i + k]] - avg), {1, NN-k}] ;
]

ListPlot[task5a, PlotLabel ->"K estimator for AR(2) normal distribution", Joined -> True, PlotRange ->All, AxesLabel -> {"k", "K(k)"}] ;

错误信息

以上代码生成以下错误消息 Sum::itraw,

看起来,for 循环有问题。

看不懂

如@agentyp 所述。问题是在两个地方求和索引。执行此代码后程序正常工作。

NN = 2000;
mu = 0;
sigma = 10;
task3a = Table[Random[NormalDistribution[mu, sigma]], {NN}];
ListPlot[task3a, AxesLabel -> {" No.obs.", "value of the obs"}, 
  PlotLabel -> " Normal Distribution"];

a = 0.6;
b = -0.45;

task4a = Table[0, {NN}];
task4a[[1]] = task3a[[1]];
task4a[[2]] = a*task4a[[1]] + task3a[[2]];
For[i = 3, i <= NN, i++, 
 task4a[[i]] = a*task4a[[i - 1]] + b*task4a[[i - 2]] + task3a[[i]];]
ListPlot[task4a, AxesLabel -> {"No.obs.", "value of the obs"}, 
  PlotLabel -> "Autoregression process for norm.dist. white noise"];

(**************************************************)
avg = (1/NN)*
   Sum[task4a[[i]], {i, 1, NN}];

task5a = Table[0, {33}];

For[k = 0, k <= 32, k++, 
 task5a[[k + 1]] = (1/(NN - k))*
    Sum[(task4a[[i]] - avg)*(task4a[[i + k]] - avg), {i, 1, NN - k}];]

ListPlot[task5a, 
 PlotLabel -> "K estimator for AR(2) normal distribution", 
 Joined -> True, PlotRange -> All, AxesLabel -> {"k", "K(k)"}]