用python计算抛物线
h 是 这个 x 坐标 哪里 这个 抛物线 触碰 这个 x 轴 和 K 是 这个 Y 坐标 哪里 这个 抛物线 交叉 这个 Y 轴 和 协调 是 A. 列表 属于 x 协调 沿着 这个 专业 轴 这个 功能 返回 A. 列表 属于 Y 协调 使用 这个 方程式 展示 在下面 那里 将 是 一 Y 坐标 对于 每个 x 坐标 在里面 这个 列表 属于 x 坐标用python计算抛物线,python,math,python-2.7,Python,Math,Python 2.7,h 是 这个 x 坐标 哪里 这个 抛物线 触碰 这个 x 轴 和 K 是 这个 Y 坐标 哪里 这个 抛物线 交叉 这个 Y 轴 和 协调 是 A. 列表 属于 x 协调 沿着 这个 专业 轴 这个 功能 返回 A. 列表 属于 Y 协调 使用 这个 方程式 展示 在下面 那里 将 是 一 Y 坐标 对于 每个 x 坐标 在里面 这个 列表 属于 x 坐标 def parabola(h, k, xCoordinates): 我知道如何使用python,因为我已经计算了面积 y(x, h, k
def parabola(h, k, xCoordinates):
我知道如何使用python,因为我已经计算了面积
y(x, h, k) = a(x − h)2, where a =k/h2
但是上面的问题伤害了我,因为这是纯粹的数学,我只需要一点帮助你可以使用平方值:
def computeArea(y_vals, h):
i=1
total=y_vals[0]+y_vals[-1]
for y in y_vals[1:-1]:
if i%2 == 0:
total+=2*y
else:
total+=4*y
i+=1
return total*(h/3.0)
y_values=[13, 45.3, 12, 1, 476, 0]
interval=1.2
area=computeArea(y_values, interval)
print "The area is", area
其中,**
幂运算的值大于乘法或除法
所以对于一系列的x
坐标,那就是:
y = (k / h ** 2) * (x - h) ** 2
Martijn Pieters给出的答案是好的 如果您对这个概念有点纠结,我发现这个例子很容易理解(使用顶点形式方程): 你可以用pylab来绘制它
我在这里假设你方程中的2
2
s是指数?那么a(x-h)
平方,那么k/h
的哪个部分是平方的呢<代码>仅h还是整个分区?我的抛物线数学是。。rusty.您可以在此处使用,因此something**2
将something
@MartijnPieters置于k/h中,仅在h上使用正方形,在(x-h)上使用正方形
def parabola(h, k, xCoordinates):
return [(k / h ** 2) * (x - h) ** 2 for x in xCoordinates]
x = range(-10,10)
y = []
a = 2 # this is the positive or negative curvature
h = 0 # horizontal offset: make this term +/- to shift the curve "side to side"
k = 0 # vertical offset: make this term +/- to shift the curve "up to down"
for xi in x:
y.append(a * (xi + h)** 2 + k)