3
def parabola(h, k, xCoordinates):

h は放物線が x 軸に接する x 座標、k は放物線が y 軸と交差する y 座標、xCoordinates は主軸に沿った x 座標のリストです。この関数は、以下に示す式を使用して y 座標のリストを返します。x 座標のリストには、x 座標ごとに 1 つの y 座標があります。

y(x, h, k) = a(x − h)2, where a =k/h2

私はすでに面積を計算しているので、Pythonで作業する方法を知っています。

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

しかし、上記の質問は純粋な数学であるため、私を傷つけています。ちょっとした助けが欲しいだけです

4

2 に答える 2

2

Martijn Pieters の回答は適切です。

概念に少し苦労している場合、この例は非常に理解しやすいと思います(頂点形式の方程式を使用):

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)

pylab でプロットできます。

于 2013-07-16T22:32:24.333 に答える
2

**累乗演算子を使用して値を二乗できます。

y = (k / h ** 2) * (x - h) ** 2

ここで、**べき乗は掛け算や割り算よりも優先されます。

したがって、一連のx座標の場合、次のようになります。

def parabola(h, k, xCoordinates):
    return [(k / h ** 2) * (x - h) ** 2 for x in xCoordinates]
于 2013-03-23T13:50:53.060 に答える