【发布时间】:2017-05-03 21:08:40
【问题描述】:
我正在通过多个点计算机翼的浮力。为此,我有特定的表面和气压数据。我现在想要通过这样的循环将计算值存储在变量中:
w = 0.7
# air pressure data
pt = np.array([0, -18.63, -80.41, -88.25, 90.21, -95.61])
pb = np.array([-112.28, 34.32, -101.98, -85.31, -3.33, 11.47, 14.71])
#top wing x-pos.
xt = np.array([11, 9.1, 6.85, 4.7, 1.7, 0.6, 1.9])
#bottom wing x-pos.
xb = np.array([2.85,0.8, 0.85, 2.5, 4.225, 6.7, 9.025, 11])
#top wing y-pos.
yt = np.array([1, 2.1, 3.05, 3.8, 3.7, 2.1, 1])
#bottom wing y-pos.
yb = np.array([4.05, 3, 1.55, 0.95, 1.125, 1.3, 1.225,1])
for i in range(0,5):
at[i] = sqrt( (xt[i] - xt[i+1]) ** 2 + (yt[i] - yt[i+1]) **2 ) * w
ab[i] = sqrt( (xb[i] - xb[i+1]) ** 2 + (yb[i] - yb[i+1]) **2 ) * w
在左边它应该创建多个变量,如下所示:
at0 = ...
:
:
at5 = ...
ab0 = ...
:
:
ab5 = ...
在右侧,它处理np.array()s 中存储的数字
这给出了这个错误:NameError: name 'at' is not defined
然后像这样继续:
for x in range(0,5):
Ft = sum( at[x] * pt[x] )
Fb = sum( ab[x] * pb[x] )
直到现在我都试图用字典来做这件事,在一行中给出循环......但它不起作用。
顺便问一下:我使用np.sum() 和np.sqrt() 而不是使用sum() 和sqrt() 有关系吗?
非常感谢!
【问题讨论】:
-
您的问题不清楚。什么不起作用?如果您可以提供Minimal, Complete, and Verifiable example,这将有所帮助
-
“它不起作用”不是一个充分的问题陈述。请详细说明。
-
请显示代码 sn-p 以显示问题以及该代码导致的完整回溯。
标签: python python-3.x numpy variables for-loop