主题:为什么两种方法的结果不一样??
大家好,我最近写了一个计算相关函数的程序。按照归一化的相关函数的定义
A=(a(t)*a(0))/(a(0)*a(0)),我采用了两种平均的方法,第一种是先分别计算a(t)*a(0)的和以及a(0)*a(0)的和,然后结果相除。第二种是先计算a(t)*a(0))/(a(0)*a(0),然后将所有的a(t)*a(0))/(a(0)*a(0)的求和,再平均,本想能得到相同的结果,可是两次输出的结果又很大区别。请大家帮忙看看是哪里出了问题。
我的程序是:
do i=1,10000 (粒子数)
do ntel=1,npoints (共有npoints个数据)
if (确定timeorigin的条件) then
t0=t0+1
time0(t0)=ntel
A0(t0)=A(ntel)
do t=1,t0
delt=ntel-time0(t)+1
tcf(delt)=tcf(delt)+A(ntel)*A0(t)
tcf0(delt)=tcf0(delt)+A0(t)*A0(t)
acf(delt)=acf(delt)+(A(ntel)*A0(t))/(A(t)*A0(t))
enddo
endif
enddo
enddo
do ical=1,npoints
WRITE(*,*) tcf(ical)=(tcf(ical)/nparticle*ntime(ical)/(tcf0(ical)&/nparticle*ntime(ical)
WRITE(*,*) acf(ical)=acf(ical)/nparticle*ntime(ical)
enddo
可是输出的结果却又很大差别,下面是结果:
0.0000000000000000 1.0000000000000000
0.0000000000000000 1.14207400639561443E-004
1.0000000149011612 0.67655786350148372
1.0000000149011612 7.72679149727596715E-005
2.0000000298023224 0.62686567164179108
2.0000000298023224 7.15926989083817998E-005
3.0000000447034836 0.60360360360360366
3.0000000447034836 6.89359985842397961E-005
4.0000000596046448 0.58610271903323263
4.0000000596046448 6.69372680485647080E-005
5.0000000745058060 0.57012195121951215
5.0000000745058060 6.51121460963353292E-005
6.0000000894069672 0.55828220858895705
6.0000000894069672 6.37599598662582241E-005
7.0000001043081284 0.54629629629629639
7.0000001043081284 6.23910799790196834E-005
8.0000001192092896 0.51552795031055898
8.0000001192092896 5.88771071620099369E-005
9.0000001341104507 0.52187499999999998
9.0000001341104507 5.96019872087711250E-005
10.000000149011612 0.52515723270440251
10.000000149011612 5.99768424742350986E-005
A=(a(t)*a(0))/(a(0)*a(0)),我采用了两种平均的方法,第一种是先分别计算a(t)*a(0)的和以及a(0)*a(0)的和,然后结果相除。第二种是先计算a(t)*a(0))/(a(0)*a(0),然后将所有的a(t)*a(0))/(a(0)*a(0)的求和,再平均,本想能得到相同的结果,可是两次输出的结果又很大区别。请大家帮忙看看是哪里出了问题。
我的程序是:
do i=1,10000 (粒子数)
do ntel=1,npoints (共有npoints个数据)
if (确定timeorigin的条件) then
t0=t0+1
time0(t0)=ntel
A0(t0)=A(ntel)
do t=1,t0
delt=ntel-time0(t)+1
tcf(delt)=tcf(delt)+A(ntel)*A0(t)
tcf0(delt)=tcf0(delt)+A0(t)*A0(t)
acf(delt)=acf(delt)+(A(ntel)*A0(t))/(A(t)*A0(t))
enddo
endif
enddo
enddo
do ical=1,npoints
WRITE(*,*) tcf(ical)=(tcf(ical)/nparticle*ntime(ical)/(tcf0(ical)&/nparticle*ntime(ical)
WRITE(*,*) acf(ical)=acf(ical)/nparticle*ntime(ical)
enddo
可是输出的结果却又很大差别,下面是结果:
0.0000000000000000 1.0000000000000000
0.0000000000000000 1.14207400639561443E-004
1.0000000149011612 0.67655786350148372
1.0000000149011612 7.72679149727596715E-005
2.0000000298023224 0.62686567164179108
2.0000000298023224 7.15926989083817998E-005
3.0000000447034836 0.60360360360360366
3.0000000447034836 6.89359985842397961E-005
4.0000000596046448 0.58610271903323263
4.0000000596046448 6.69372680485647080E-005
5.0000000745058060 0.57012195121951215
5.0000000745058060 6.51121460963353292E-005
6.0000000894069672 0.55828220858895705
6.0000000894069672 6.37599598662582241E-005
7.0000001043081284 0.54629629629629639
7.0000001043081284 6.23910799790196834E-005
8.0000001192092896 0.51552795031055898
8.0000001192092896 5.88771071620099369E-005
9.0000001341104507 0.52187499999999998
9.0000001341104507 5.96019872087711250E-005
10.000000149011612 0.52515723270440251
10.000000149011612 5.99768424742350986E-005