24小时热门版块排行榜    

查看: 472  |  回复: 2

astringent

铜虫 (著名写手)


[交流] 【求助】为什么两种写法得到的值不一样?

为什么把if语句放到不同的位置,结果就不一样了呢?请大家帮忙分析一下,多谢。
写法一(判断语句为h0(t)/=0):
t0=0
             do ntel=1, npoints
         
               neworig = .false.
               if (t0.eq.0) then
                   neworig = .true.
               elseif (ntel-time0(t0).eq.it0)then
                   neworig = .true.
               endif

               if (neworig) then
                  t0 = t0 + 1         ! update number of t=0
                  time0(t0) = ntel    ! store the time of t=0
                  h0(t0) = h(ntel)
                endif
         
                do t=1, t0             ! update tcf for t=0
                   delt=ntel-time0(t)+1 ! actual time minus t=0
                   if(h0(t)/=0.and.(delt.lt.npoints)) then
                      ntime(delt) = ntime(delt)+1d0
                      tcf(delt)=tcf(delt)+h(ntel)*h0(t)
                      tcf0(delt)=tcf0(delt)+h0(t)*h0(t)
                    endif
                 enddo               
              enddo
写法二(判断语句为if (h(ntel)/=0) then)
t0=0
             do ntel=1, npoints
         
               neworig = .false.
               if (h(ntel)/=0) then
               if (t0.eq.0) then
                   neworig = .true.
               elseif (ntel-time0(t0).eq.it0)then
                   neworig = .true.
               endif
              endif

               if (neworig) then
                  t0 = t0 + 1         ! update number of t=0
                  time0(t0) = ntel    ! store the time of t=0
                  h0(t0) = h(ntel)
                endif
         
                do t=1, t0             ! update tcf for t=0
                   delt=ntel-time0(t)+1 ! actual time minus t=0
                   if(delt.lt.npoints) then
                      ntime(delt) = ntime(delt)+1d0
                      tcf(delt)=tcf(delt)+h(ntel)*h0(t)
                      tcf0(delt)=tcf0(delt)+h0(t)*h0(t)
                    endif
                 enddo               
              enddo
回复此楼

» 猜你喜欢

» 抢金币啦!回帖就可以得到:

查看全部散金贴

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zhuwei04

木虫 (正式写手)


astringent(金币+10): 2011-02-13 20:36:36
h(1) 能保证/=0吗?
如果和h(1)=0,写法一比较好吧,至少能保证do t=1, t0 这句不出错
2楼2011-02-13 10:18:59
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
★ ★ ★
astringent(金币+10): 2011-02-13 20:36:39
余泽成(金币+3): 谢谢参与应助! 2011-02-20 18:22:58
你这个程序片断有太多的东西没有交待,所以不能从程序片断上来解读

在下面的这段代码中,你加了一个判断才能进行 neworig 的赋值,但在方法一中,没有这样的判断,因此,可能会导致 neworig 的值在两个程序中不一样,那么可能会直接影响最后的结果……
CODE:
             if (h(ntel)/=0) then
               if (t0.eq.0) then
                   neworig = .true.
               elseif (ntel-time0(t0).eq.it0)then
                   neworig = .true.
               endif
              endif

3楼2011-02-13 10:24:20
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 astringent 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 0703化学调剂,求各位老师收留 +8 秋有木北 2026-03-14 8/400 2026-03-16 15:21 by 哦哦123
[教师之家] 焦虑 +7 水冰月月野兔 2026-03-13 9/450 2026-03-16 10:00 by Quakerbird
[考研] 22408总分284求调剂 +3 InAspic 2026-03-13 3/150 2026-03-15 11:10 by zhq0425
[考研] 289求调剂 +5 步川酷紫123 2026-03-11 5/250 2026-03-15 00:45 by kruisytel
[考研] 297一志愿上交085600求调剂 +5 指尖八千里 2026-03-14 5/250 2026-03-14 17:26 by a不易
[考研] 328,0703考生求调剂,一志愿为东北师范大学 +4 观素律 2026-03-09 5/250 2026-03-14 01:24 by JourneyLucky
[考研] 环境调剂 +6 晓看天暮看云 2026-03-09 6/300 2026-03-14 01:16 by JourneyLucky
[考研] 考研材料与化工,求调剂 +8 戏精丹丹丹 2026-03-09 8/400 2026-03-14 01:14 by JourneyLucky
[考研] 307求调剂 +7 超级伊昂大王 2026-03-10 7/350 2026-03-14 00:49 by JourneyLucky
[考研] 材料工程专硕,一志愿中国矿业大学,总分314,求调剂 +5 无懈可击的巨人 2026-03-10 5/250 2026-03-14 00:37 by JourneyLucky
[考研] 2026考研调剂+本科延边大学+山东大学+生物化学与分子生物学+有项目经验 +3 ccdsscjy 2026-03-10 3/150 2026-03-14 00:12 by JourneyLucky
[考研] 工科,求调剂 +3 我887 2026-03-11 3/150 2026-03-13 21:39 by JourneyLucky
[考研] 材料工程调剂 +4 咪咪空空 2026-03-11 4/200 2026-03-13 19:57 by JourneyLucky
[考研] 302求调剂 +6 负心者当诛 2026-03-11 6/300 2026-03-13 16:11 by JourneyLucky
[考研] 求调剂 +3 程雨杭 2026-03-12 3/150 2026-03-13 15:06 by JourneyLucky
[考研] 土木第一志愿276求调剂,科研和技能十分丰富,求新兴方向的导师收留 +3 土木小天才 2026-03-12 3/150 2026-03-13 15:01 by JourneyLucky
[考研] 308求调剂 +3 是Lupa啊 2026-03-12 3/150 2026-03-13 14:30 by 求调剂zz
[考研] 277求调剂 +4 anchor17 2026-03-12 4/200 2026-03-13 11:15 by 白夜悠长
[考博] 26读博 +4 Rui135246 2026-03-12 10/500 2026-03-13 07:15 by gaobiao
[考博] 2026年博士申请 +3 QwQwQW10 2026-03-11 3/150 2026-03-12 17:58 by gxch43
信息提示
请填处理意见