# Questions regarding parabolic equations

Discussion in 'Web Design' started by MateoLeo, Sep 10, 2017.

1. ### MateoLeo Registered Member

Joined:
Sep 10, 2017
Messages:
6
0
I'm trying to create a function that will return y in increasing and decreasing the value, in proportion to a parabolic function.
So really just have y increase and decrease along the line it creates.
I'm just trying to make an image move along my screen in a manner other than only to the left in one speed. If there is a better way to create this then please let me know!

So far I found this online but I have a vague idea of what it will return.

PHP:
``` d = (b ** 2) - (4 * a * c)    y = (-b - cmath.sqrt(d)) / (2 * a)    return float(y) ```

#1
2. ### Andrew80 Registered Member

Joined:
Sep 10, 2017
Messages:
6
``` import cmathdef quadratic(a, b, c):    d = cmath.sqrt(b**2 - (4 * a * c))    return {(-b + d)/(2*a), (-b - d)/(2*a)}Graphing a parabola is easy. If you want to just find a few points, you can just apply the function for any value of x. Although the graph is usually shown diverting from the vertex, so calculate the vertex (h,k) with h=-b/2a and k=f(h), then just make a range of points up or down the x axis.PHP Code:import cmathclass Function:    def __init__(self, a, b, c):        self.a, self.b, self.c = a, b, c    def __call__(self, x):        return (self.a * x**2) + (self.b * x) + self.c    @staticmethod    def frange(x, y, jump=1.0):        while x < y:            yield x            x += jump    @property    def vertex(self):        h = -self.b / (2 * self.a)        k = self(h)        return h, k    def points(self, pairs=3, step=1.0):        h, k = self.vertex        x1 = list(self.frange(h-(pairs * step), h, step))        x2 = list(self.frange(h+1, h+(step * (pairs+1)), step))        y1, y2 = list(map(self, x1)), list(map(self, x2))        return list(zip(x1, y1)) + [(h, k)] + list(zip(x2, y2))This would generate points on a graph f(x) = (x^2)/2 + 2x - 1PHP Code:f = Function(0.5, 2, -1)print(f.points())print(f.points(6))print(f.points(step=2))  ```