24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 480  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[有机交流] 考研调剂 +6 watb 2026-03-26 6/300 2026-03-30 16:32 by herarysara
[考研] 085602化工求调剂(331分) +6 111@127 2026-03-30 6/300 2026-03-30 16:26 by 星空星月
[考研] 300求调剂,材料科学英一数二 +18 leaflight 2026-03-24 18/900 2026-03-30 15:59 by wangjy2002
[考研] 一志愿南昌大学324求调剂 +8 hanamiko 2026-03-27 8/400 2026-03-30 14:09 by JourneyLucky
[考研] 生物技术与工程 +7 1294608413 2026-03-25 8/400 2026-03-30 11:36 by 唐沐儿
[考研] 一志愿南开大学0710生物学359求调剂 +5 兔兔兔111223314 2026-03-29 5/250 2026-03-30 10:41 by malone0211
[考研] 一志愿哈尔滨工业大学材料与化工方向336分 +11 辰沐5211314 2026-03-26 11/550 2026-03-30 09:00 by 无际的草原
[考研] 086000生物与医药调剂 +5 Feisty。 2026-03-28 9/450 2026-03-29 12:02 by longlotian
[考研] 298求调剂 +4 种圣赐 2026-03-28 4/200 2026-03-29 08:42 by q1092522407
[考研] 081200-11408-276学硕求调剂 +6 崔wj 2026-03-26 6/300 2026-03-29 01:11 by hanserlol
[考研] 食品工程专硕一志愿中海洋309求调剂 +4 小张zxy张 2026-03-26 8/400 2026-03-28 19:25 by lbsjt
[考研] 材料与化工(0856)304求B区调剂 +8 邱gl 2026-03-27 8/400 2026-03-28 12:42 by 唐沐儿
[考研] 085405 考的11408求各位老师带走 +3 Qiu学ing 2026-03-28 3/150 2026-03-28 09:19 by 乐呵呵的追梦人
[考研] 考研调剂 +10 呼呼?~+123456 2026-03-24 10/500 2026-03-27 11:46 by wangjy2002
[考研] 一志愿郑大085600,310分求调剂 +5 李潇可 2026-03-26 5/250 2026-03-27 11:14 by 不吃魚的貓
[考研] 材料求调剂 +5 .m.. 2026-03-25 5/250 2026-03-27 11:08 by 不吃魚的貓
[考研] 求调剂 +6 林之夕 2026-03-24 6/300 2026-03-27 08:38 by hypershenger
[考研] 289求调剂 +17 硕星赴 2026-03-23 17/850 2026-03-26 16:18 by 不吃魚的貓
[考研] 打过很多竞赛,085406控制工程300分,求调剂 +3 askeladz 2026-03-26 3/150 2026-03-26 09:08 by 给你你注意休息
[考研] 材料专硕331求调剂 +4 鲜当牛 2026-03-24 4/200 2026-03-24 15:58 by JourneyLucky
信息提示
请填处理意见