Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用先前生成的元组生成新元组_Python_List_Tuples_Physics - Fatal编程技术网

Python 如何使用先前生成的元组生成新元组

Python 如何使用先前生成的元组生成新元组,python,list,tuples,physics,Python,List,Tuples,Physics,我想知道是否有人能帮我找出如何用先前生成的元组生成新元组。到目前为止,我所做的只是生成一个空元组 import math as m grav = 9.807 #[m/s**2] gravity http://physics.nist.gov/cgi-bin/cuu/Value?gn value obtained from NIST H = 1.100 #[m] Height of the posts/supports rho = 2.000 #[kg/m] density of the chai

我想知道是否有人能帮我找出如何用先前生成的元组生成新元组。到目前为止,我所做的只是生成一个空元组

import math as m
grav = 9.807 #[m/s**2] gravity http://physics.nist.gov/cgi-bin/cuu/Value?gn value obtained from NIST
H = 1.100 #[m] Height of the posts/supports
rho = 2.000 #[kg/m] density of the chain
DIS = 0.980 # distance of supports from x = 0
SEG = 10000. #number of divisions
SEGL = 2*DIS/SEG # size of segments
aa = 0.6 #[m]

#xtuple
n=0
xterms = []
xterm = -DIS
while n<=SEG:
    xterms.append(xterm)
    n+=1
    xterm = -DIS + n*SEGL
#ytuple
yterms = []
yterm = H
while n<= SEG:
    yterms.append(yterm)
    n+=1
    yterm = H + aa*m.cosh(xterms[n]/aa) -aa*m.cosh(DIS/aa)
print yterms
将数学导入为m
重力=9.807#[m/s**2]重力http://physics.nist.gov/cgi-bin/cuu/Value?gn 从NIST获得的值
H=1.100#[m]立柱/支架的高度
rho=链的2.000#[kg/m]密度
DIS=0.980#支架与x的距离=0
SEG=10000#分部数
SEGL=2*DIS/SEG#分段尺寸
aa=0.6#[m]
#X波
n=0
xterms=[]
xterm=-DIS

而n您的
yterms
为空,因为
n
距离第一个循环仍为10001

第二个while循环没有执行,因为n已经大于SEG。

谢谢你的帮助,但我设法找出了我的愚蠢错误。这是正确的做法。我手工写下了这个过程,它让我得到了这个解决方案

k=0
yterms = []
while k<=SEG:
    yterm = H + aa*m.cosh(xterms[k]/aa) -aa*m.cosh(DIS/aa)
    yterms.append(yterm)
    k+=1
print yterms
k=0
yterms=[]

而kSo这是一个家庭作业,对吗?请明确说明您的问题和您尝试过的内容,以及您遇到的错误,以显示您付出了巨大的努力。但是,如果我重新提交n=0,我会得到“IndexError:list index out range”,这是因为第二个while循环中的n变得大于“xterms”的长度。你试图说xterms[n],其中n超出了索引范围。没错,你先访问
xterms[1]
跳过
x[0]
元素。我想出来了,我会在7.5小时后发布我的解决方案。我想出来了我的问题,我会在7.5小时后发布我的解决方案,您可以使用for循环和or循环遍历k的不同值。您不必担心由于增量项的放置而导致代码失败,并且您的变量对于每个循环都是唯一的,因此无需重置。