返回列表 上一主題 發帖

[發問] 求救 有關nested loop

回復 1# drgv11
手動輸入 Cells(1,1)
手動輸入 Cells(2,1)
Cells(3,1)=cells(1,1)*4-1
Cells(4,1)=cells(2,1)/6
do until Abs(Cells(4,1)-Cells(3,1)) <=0.0005
  if Cells(4,1)-Cells(3,1) >0.0005 then cells(2,1)=cells(2,1)+0.0001
  Cells(3,1)=Cells(1,1)*4-1
  Cells(4,1)=Cells(2,1)/6
loop

若 Cells(2,1) 為正數,
且 Cells(4,1)-Cells(3,1) >0.0005 則
第1個迴圈將成為無限迴圈.

證明 :
設 Cells(1,1)=A , Cells(2,1)=B 且  Cells(4,1)-Cells(3,1) >0.0005
則
Cells(3,1)=A*4-1
Cells(4,1)=B/6
Cells(4,1)-Cells(3,1)
=B/6-(A*4-1)
=B/6-4A+1 > 0.0005
依程式下一輪 cells(2,1)=B+0.0001
Cells(4,1)-Cells(3,1)
=(B+0.0001)/6+4A+1 > B/6-4A+1 => 只會越來越大
所以 Cells(4,1)-Cells(3,1) <= 0.0005 永遠不會成立.
得證.

註 : 我不是數學家, 證明步驟非正規, 請見諒.

TOP

        靜思自在 : 愛不是要求對方,而是要由自身的付出。
返回列表 上一主題