Reputation:
def parabola(h, k, xCoordinates):
h is the x coordinate where the parabola touches the x axis and k is the y coordinate where the parabola intersects the y axis and xCoordinates is a list of x coordinates along the major axis. The function returns a list of y coordinates using the equation shown below. There will be one y coordinate for each x coordinate in the list of x coordinates.
y(x, h, k) = a(x − h)2, where a =k/h2
I know how to work in python as i already compute the area ,
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
But the question above is hurting me because its pure mathmatics , i just want little bit help
Upvotes: 3
Views: 4702
Reputation: 331
The answer given by Martijn Pieters is good.
If you're struggling a little with the concept I find this example to be very easy to understand (using the vertex form equation):
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)
You can plot it with pylab.
Upvotes: 2
Reputation: 1121446
You can use the **
power operator to square values:
y = (k / h ** 2) * (x - h) ** 2
where **
exponentiation has a higher precedence than multiplication or division.
So for a series of x
coordinates, that'd be:
def parabola(h, k, xCoordinates):
return [(k / h ** 2) * (x - h) ** 2 for x in xCoordinates]
Upvotes: 2