Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fractions
- def quadratic(a, b, c):
- s1 = ( (b**2) - (4*a*c) ) ** 0.5
- s2 = 2*a
- ret = [(-b - s1) / s2, (-b + s1) / s2]
- return ret
- def curveFromVP(vertex, point):
- """Finds a quadratic curve given vertex and point coordinate pairs.
- Returns in the format ("equation string", a), where the equation is in
- the form y=a(x-h)**2 + k."""
- vX, vY = vertex
- pX, pY = point
- aMult = (pX - vX) ** 2
- ret = fractions.Fraction(pY - vY, aMult)
- if ret == 1: retA = ""
- elif ret._denominator == 1: retA = str(ret)
- else: retA = "({})".format(ret)
- if vX == 0:
- retX = "x"
- else:
- retX = "(x{0:+})".format(-vX)
- if vY == 0:
- retY = ""
- elif vY < 0:
- retY = " - {}".format(abs(vY))
- else:
- retY = " + {}".format(abs(vY))
- retStr = "f(x) = {}{}**2{}".format(retA, retX, retY)
- return retStr, ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement