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

时间:2016-12-06 02:50:01

标签: wolfram-mathematica

enter image description here

我已经重新启动了以下内容,

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

enter image description here

看起来,for循环存在一些问题。

我无法理解。

1 个答案:

答案 0 :(得分:1)

正如@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)"}]

result

相关问题