diff --git a/src/FSharp/FindRoots.fs b/src/FSharp/FindRoots.fs index fbcacd20..41966dca 100644 --- a/src/FSharp/FindRoots.fs +++ b/src/FSharp/FindRoots.fs @@ -70,6 +70,11 @@ module FindRoots = | true, root -> Some root | false, _ -> None + let broydenWithJacobianStep jacobianStepSize maxIterations accuracy guess (f:float[]->float[]) = + match Broyden.TryFindRootWithJacobianStep(tobcl f, guess, accuracy, maxIterations, jacobianStepSize) with + | true, root -> Some root + | false, _ -> None + // simple usage let ofFunction lowerBound upperBound (f:float->float) = diff --git a/src/FSharpUnitTests/FindRootsTests.fs b/src/FSharpUnitTests/FindRootsTests.fs index d6ac588a..e612b1ca 100644 --- a/src/FSharpUnitTests/FindRootsTests.fs +++ b/src/FSharpUnitTests/FindRootsTests.fs @@ -59,6 +59,11 @@ module FindRootsTests = | Some x -> should (equalWithin 1e-1) [|0.9638680512795; 346.16369814640|] | None -> failwith "The element in array is not equal.") |> ignore + [] + let ``Bryoden with Jacobian step size should find both roots of (x - 3) * (x - 4)``() = + f |> (fun g (x:float[]) -> [|g x.[0]|]) |> FindRoots.broydenWithJacobianStep 1e-6 100 1e-14 [|1.0;|] |> shouldEqual (Some [|3.0|]) + f |> (fun g (x:float[]) -> [|g x.[0]|]) |> FindRoots.broydenWithJacobianStep 1e-6 100 1e-14 [|9.0;|] |> shouldEqual (Some [|4.0|]) + [] let ``Simple method should find both roots of (x - 3) * (x - 4)``() = f |> FindRoots.ofFunction -5.0 3.5 |> Option.get |> should (equalWithin 1e-8) 3.0