1.2.3-SNAPSHOT Arrow_down_16x16

solve-quadratic

incanter.core

  • (solve-quadratic a b c)

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

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source incanter/core.clj:2271 top

(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)])))
Vars in incanter.core/solve-quadratic: defn let
Used in 0 other vars

Comments top

No comments for solve-quadratic. Log in to add a comment.