SetDirectory["C:\\Users\\Yoon\\Documents\\teaching\\ZCE111\\1011SEM2\\notes\\demo_3Mar11"];

jlast=1000;L=10;dx=0.5;nlast=10;
tx={};
For[j=1,j≤jlast,j++,
x[j]=0.0;
tx=Append[tx,x[j]];
];(*end for j*)
BC[0]=BinCounts[tx,{-L,L,dx}];
BC[0]=BC[0]/jlast;
tx;
BC[0];
ListPlot[BC[0],Filling->Axis];

For[n=1,n≤nlast,n++,
tx={};
For[j=1,j≤jlast,j++,
q=Random[Integer];
If[q==0,x[j]=x[j]+1,x[j]=x[j]-1];(*end if*)(* Shift the walker randomly*)
tx=Append[tx,x[j]];
];(*end for j*)
BC[n]=BinCounts[tx,{-L,L,dx}];
BC[n]=BC[n]/jlast;
(*Print["tx = ",tx ];
Print["n, BC[n] =",n," ",BC[n]];
Print[" "];*)
];(*end for n*)

Manipulate[ListPlot[BC[n],PlotRange->{0,1},Filling->Axis],{n,0,nlast,1}]

Export["BC1.dat",BC[1]]

readBC1=Flatten[Import["BC1.dat"],1];

readBC1

n

n=ToString[n]

NumberQ[n]

name="Myname"<>"Yourname"<>n<>".dat";

name

For[m=0,m≤nlast,m++,
nstring=ToString[m];
name="BC"<>nstring<>".dat";
Export[name,BC[n]]
]