24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 483  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 材料调剂 +7 一样YWY 2026-04-05 8/400 2026-04-05 21:20 by 学员8dgXkO
[考研] 求调剂 一志愿西南交通大学085701环境工程 282分 +7 多多爱吃汉堡 2026-04-04 7/350 2026-04-05 19:47 by 福农资环_环境基
[考研] 材料专硕283求调剂 +14 试试看呗 2026-04-04 15/750 2026-04-05 19:21 by jkddd
[考研] 266分,一志愿电气工程,本科材料,求材料专业调剂 +8 哇呼哼呼哼 2026-04-02 9/450 2026-04-05 17:14 by lbsjt
[考研] 0703化学调剂325分 +9 15771691647 2026-04-04 9/450 2026-04-05 11:39 by 猪会飞
[考研] 295求调剂 +10 xndjjj 2026-04-04 10/500 2026-04-05 11:19 by 猪会飞
[考研] 283分求调剂 +9 试试看呗 2026-04-04 9/450 2026-04-05 10:27 by 果冻大王
[考研] 能动调剂326专硕 +4 wan112233 2026-04-04 4/200 2026-04-04 22:47 by yu221
[考研] 282电子信息0854专硕调剂 +4 202451007219 2026-04-02 6/300 2026-04-04 21:55 by laoshidan
[考研] 283分材料与化工求调剂 +29 罗KAKA 2026-04-02 29/1450 2026-04-03 23:56 by userper
[考研] 一志愿北京交通大学材料工程总分358 +4 cs0106 2026-04-03 4/200 2026-04-03 13:41 by 百灵童888
[考研] 土木水利328分求调剂 +6 疾风知劲草666 2026-04-02 6/300 2026-04-03 11:38 by znian
[考研] 085600 295分求调剂 +19 W55j 2026-03-30 23/1150 2026-04-03 09:53 by 千千运气
[考研] 一志愿厦门大学材料工程专硕354找调剂!!! +8 贝呗钡钡 2026-03-30 8/400 2026-04-03 09:41 by hypershenger
[考研] 285求调剂 +8 AZMK 2026-04-02 11/550 2026-04-02 20:16 by yulian1987
[考研] 0710生物学,325求调剂 +3 mkkkkkl 2026-04-01 3/150 2026-04-02 09:48 by Jaylen.
[考研] 379求调剂 +3 ?苦瓜不苦 2026-04-01 3/150 2026-04-01 20:09 by 暮云清寒
[考研] 一志愿北交材料工程总分358 +5 cs0106 2026-04-01 7/350 2026-04-01 11:45 by wangjy2002
[考研] 一志愿北京科技大学085601材料工程英一数二初试总分335求调剂 +5 双马尾痞老板2 2026-03-31 5/250 2026-04-01 09:04 by oooqiao
[考研] 吉大生物学326分求调剂 +3 sunnyupup 2026-03-31 3/150 2026-03-31 09:28 by longlotian
信息提示
请填处理意见