2016-12-06 8 views
0

enter image description here원시 오브젝트 1, I는 다음과 같이이를 rewitten 한

반복자로서 사용될 수

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

Sum' '의'반복자이어야 {I, 1, K-NN}' – agentp

답변

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