(defn solve-quadratic
"
Returns a vector with the solution to x from the quadratic
equation, a*x^2 + b*x + c.
Arguments:
a, b, c: coefficients of a qaudratic equation.
Examples:
;; -2*x^2 + 7*x + 15
(quadratic-formula -2 7 15)
;; x^2 + -2*x + 1
(quadratic-formula 1 -2 1)
References:
http://en.wikipedia.org/wiki/Quadratic_formula
"
([a b c]
(let [t1 (- 0 b)
t2 (sqrt (- (* b b) (* 4 a c)))
t3 (* 2 a)]
[(/ (- t1 t2) t3)
(/ (+ t1 t2) t3)])))
Comments top
No comments for solve-quadratic. Log in to add a comment.