Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168733
Image: ubuntu2004

The Solutions of the Quadratic Equation

Lauri Ruotsalainen, 2010

Pictures:

# The Solutions of the Quadratic Equation # Lauri Ruotsalainen, 2010 @interact def quadratic_eqn( A = slider(-7, 7, 1, 1), B = slider(-7, 7, 1, 1), C = slider(-7, 7, 1, -2) ): f(x) = A*x^2 + B*x + C html("$%s = 0$" %f(x)) show(plot(f(x), x, (-10, 10), ymin=-10, ymax=10), aspect_ratio=1, figsize=4) d = B^2 - 4*A*C if d < 0: color = "Red" sol = "\\text{no solution.}" elif d == 0: color = "Blue" sol = -B/(2*A) else: color = "Green" a = (-B+sqrt(B^2-4*A*C))/(2*A) b = (-B-sqrt(B^2-4*A*C))/(2*A) sol = "\\begin{cases}%s\\\%s\\end{cases}" % (latex(a), latex(b)) if B<0: dis1 = "(%s)^2-4*%s*%s" % (B, A, C) else: dis1 = "%s^2-4*%s*%s" % (B, A, C) dis2 = "\color{%s}{%s}" % (color, d) html("$Ax^2 + Bx + C = 0$") html( "$x = \\frac{-B\pm\sqrt{B^2-4AC}}{2A} = " "\\frac{-%s\pm\sqrt{%s}}{2*%s} = " "\\frac{-%s\pm\sqrt{%s}}{%s} = " "%s$" % (B, dis1, A, B, dis2, 2*A, sol) )