Skip to content

Instantly share code, notes, and snippets.

@PatrickMcDonald
Created July 29, 2014 12:56
Show Gist options
  • Save PatrickMcDonald/b3465e3016a3dc29bbf1 to your computer and use it in GitHub Desktop.
Save PatrickMcDonald/b3465e3016a3dc29bbf1 to your computer and use it in GitHub Desktop.
#r "System.Numerics"
open System.Numerics
/// Find the roots of ax² + bx + c
let quadraticRoots a b c =
let ``√ B² - 4ac`` = sqrt (b * b - 4.0 * a * c)
let ``2a`` = 2.0 * a
(-b + ``√ B² - 4ac``) / ``2a``, (-b - ``√ B² - 4ac``) / ``2a``
let complex a = new Complex(a, 0.)
/// Find the complex roots of ax² + bx + c
let quadraticRootsCplx a b c =
let ax, bx, cx = complex a, complex b, complex c
let ``√ B² - 4ac`` = sqrt (bx * bx - Complex(4.,0.) * ax * cx)
let ``2a`` = Complex(2.,0.) * ax
(-bx + ``√ B² - 4ac``) / ``2a``, (-bx - ``√ B² - 4ac``) / ``2a``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment