Python努力让方程循环

时间:2016-12-14 15:54:04

标签: python python-2.7

我正在尝试运行一组公式并将结果存储到列表中。它需要使用单独列表中的新值来执行此操作。我可以让它正确运行一次,但之后它只是每次重新创建相同的值,我很难理解为什么。

    alts=[50000,30000,10000]
    alte=[30000,10000,0]
    time=[]
    mins=[0,100,30]
    maxs= [0,0,30]
    Va=[]
    landing= []
    vMax=500
    vMaxL= []

    while vMax < 601:
       vMaxL.append(vMax)
       maxs[0]= vMax
       maxs[1]= vMax

         for i in range (0, len(alts)):
             Va.append((mins[i]+maxs[i])/2)
             time.insert(0,(alts[i]-alte[i])/Va[i])
             timetaken= time[0] + time [1] + time[2]
             landing.append(timetaken)

      vMax= vMax + 20

   print vMax
   print maxs
   print vMaxL
   print timetaken
   print landing

输出如下:

  620
  [600, 600, 30]
  [500, 520, 540, 560, 580, 600]
  479
  [479, 479, 479, 479, 479, 479]

1 个答案:

答案 0 :(得分:0)

我想问题是你总是及时对前3项进行总结。

不应该这样吗?

import numpy as np

alts=[50000,30000,10000]
alte=[30000,10000,0]
time=list()
mins = np.array([0,100,30])
maxs = np.array([0,0,30])
Va = list()
landing = list()
vMax=500
vMaxL= list()

while vMax < 601:
    vMaxL.append(vMax)
    maxs[0]= vMax
    maxs[1]= vMax

    for i in range (0, len(alts)):
         Va.append((mins[i]+maxs[i])/2)
         time.insert(0,(alts[i]-alte[i])/Va[i])
         timetaken= np.sum(time)
         landing.append(timetaken)

    vMax= vMax + 20

print ('vMax:', vMax)
print ('maxs:', maxs)
print ('vMaxL:', vMaxL)
print ('timetaken:', timetaken)
print ('landing',landing)

输出结果为:

vMax: 620
maxs: [600 600  30]
vMaxL: [500, 520, 540, 560, 580, 600]
timetaken: 2880.0
landing [80.0, 146.66666666666669, 480.0, 560.0, 626.66666666666663, 959.99999999999989, 1040.0, 1106.6666666666667, 1440.0, 1520.0, 1586.6666666666667, 1920.0, 2000.0, 2066.666666666667, 2400.0, 2480.0, 2546.666666666667, 2879.9999999999995]