Browse Source

RootFinding: Add bisection and non-robust newton raphson to F# module

v2
Christoph Ruegg 13 years ago
parent
commit
8573ba072e
  1. 15
      src/FSharp/FindRoots.fs

15
src/FSharp/FindRoots.fs

@ -41,11 +41,26 @@ module FindRoots =
// direct algorithms // 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) = let brent maxIterations accuracy lowerBound upperBound (f:double->double) =
match Brent.TryFindRoot(tobcl f, lowerBound, upperBound, accuracy, maxIterations) with match Brent.TryFindRoot(tobcl f, lowerBound, upperBound, accuracy, maxIterations) with
| true, root -> Some root | true, root -> Some root
| false, _ -> None | 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) = 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 match RobustNewtonRaphson.TryFindRoot(tobcl f, tobcl df, lowerBound, upperBound, accuracy, maxIterations, subdivision) with
| true, root -> Some root | true, root -> Some root

Loading…
Cancel
Save