From 8573ba072e0f6a3021e66d9bdd21b822ff5f0e79 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sat, 13 Jul 2013 19:54:40 +0200 Subject: [PATCH] RootFinding: Add bisection and non-robust newton raphson to F# module --- src/FSharp/FindRoots.fs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/FSharp/FindRoots.fs b/src/FSharp/FindRoots.fs index 9ec6173f..5cd71f0a 100644 --- a/src/FSharp/FindRoots.fs +++ b/src/FSharp/FindRoots.fs @@ -41,11 +41,26 @@ module FindRoots = // direct algorithms + let bisection maxIterations accuracy lowerBound upperBound (f:double->double) = + match Bisection.TryFindRoot(tobcl f, lowerBound, upperBound, accuracy, maxIterations) with + | true, root -> Some root + | false, _ -> None + let brent maxIterations accuracy lowerBound upperBound (f:double->double) = match Brent.TryFindRoot(tobcl f, lowerBound, upperBound, accuracy, maxIterations) with | true, root -> Some root | false, _ -> None + let newtonRaphson maxIterations accuracy lowerBound upperBound (f:double->double) (df:double->double) = + match NewtonRaphson.TryFindRoot(tobcl f, tobcl df, 0.5 * (lowerBound + upperBound), lowerBound, upperBound, accuracy, maxIterations) with + | true, root -> Some root + | false, _ -> None + + let newtonRaphsonGuess maxIterations accuracy guess (f:double->double) (df:double->double) = + match NewtonRaphson.TryFindRoot(tobcl f, tobcl df, guess, Double.MinValue, Double.MaxValue, accuracy, maxIterations) with + | true, root -> Some root + | false, _ -> None + let newtonRaphsonRobust maxIterations subdivision accuracy lowerBound upperBound (f:double->double) (df:double->double) = match RobustNewtonRaphson.TryFindRoot(tobcl f, tobcl df, lowerBound, upperBound, accuracy, maxIterations, subdivision) with | true, root -> Some root