diff --git a/Project.toml b/Project.toml index 12a8ec5d8..50b805590 100644 --- a/Project.toml +++ b/Project.toml @@ -31,6 +31,14 @@ SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35" StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5" +[sources] +BracketingNonlinearSolve = {path = "lib/BracketingNonlinearSolve"} +NonlinearSolveBase = {path = "lib/NonlinearSolveBase"} +NonlinearSolveFirstOrder = {path = "lib/NonlinearSolveFirstOrder"} +NonlinearSolveQuasiNewton = {path = "lib/NonlinearSolveQuasiNewton"} +NonlinearSolveSpectralMethods = {path = "lib/NonlinearSolveSpectralMethods"} +SimpleNonlinearSolve = {path = "lib/SimpleNonlinearSolve"} + [weakdeps] FastLevenbergMarquardt = "7a0df574-e128-4d35-8cbd-3d84502bf7ce" FixedPointAcceleration = "817d07cb-a79a-5c30-9a31-890123675176" diff --git a/lib/BracketingNonlinearSolve/Project.toml b/lib/BracketingNonlinearSolve/Project.toml index 5be59caf6..6475637fb 100644 --- a/lib/BracketingNonlinearSolve/Project.toml +++ b/lib/BracketingNonlinearSolve/Project.toml @@ -11,6 +11,9 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" +[sources] +NonlinearSolveBase = {path = "../NonlinearSolveBase"} + [weakdeps] ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" diff --git a/lib/BracketingNonlinearSolve/src/muller.jl b/lib/BracketingNonlinearSolve/src/muller.jl index edde280de..fbd87c34d 100644 --- a/lib/BracketingNonlinearSolve/src/muller.jl +++ b/lib/BracketingNonlinearSolve/src/muller.jl @@ -8,8 +8,8 @@ initial guesses `(left, middle, right)` for the root. ### Keyword Arguments -- `middle`: the initial guess for the middle point. If not provided, the - midpoint of the interval `(left, right)` is used. + - `middle`: the initial guess for the middle point. If not provided, the + midpoint of the interval `(left, right)` is used. """ struct Muller{T} <: AbstractBracketingAlgorithm middle::T @@ -18,7 +18,7 @@ end Muller() = Muller(nothing) function CommonSolve.solve(prob::IntervalNonlinearProblem, alg::Muller, args...; - abstol = nothing, maxiters = 1000, kwargs...) + abstol = nothing, maxiters = 1000, kwargs...) @assert !SciMLBase.isinplace(prob) "`Muller` only supports out-of-place problems." xᵢ₋₂, xᵢ = prob.tspan xᵢ₋₁ = isnothing(alg.middle) ? (xᵢ₋₂ + xᵢ) / 2 : alg.middle @@ -32,19 +32,19 @@ function CommonSolve.solve(prob::IntervalNonlinearProblem, alg::Muller, args...; abstol = abs(NonlinearSolveBase.get_tolerance( xᵢ₋₂, abstol, promote_type(eltype(xᵢ₋₂), eltype(xᵢ)))) - for _ ∈ 1:maxiters - q = (xᵢ - xᵢ₋₁)/(xᵢ₋₁ - xᵢ₋₂) - A = q*fxᵢ - q*(1 + q)*fxᵢ₋₁ + q^2*fxᵢ₋₂ - B = (2*q + 1)*fxᵢ - (1 + q)^2*fxᵢ₋₁ + q^2*fxᵢ₋₂ - C = (1 + q)*fxᵢ + for _ in 1:maxiters + q = (xᵢ - xᵢ₋₁) / (xᵢ₋₁ - xᵢ₋₂) + A = q * fxᵢ - q * (1 + q) * fxᵢ₋₁ + q^2 * fxᵢ₋₂ + B = (2 * q + 1) * fxᵢ - (1 + q)^2 * fxᵢ₋₁ + q^2 * fxᵢ₋₂ + C = (1 + q) * fxᵢ - denom₊ = B + √(B^2 - 4*A*C) - denom₋ = B - √(B^2 - 4*A*C) + denom₊ = B + √(B^2 - 4 * A * C) + denom₋ = B - √(B^2 - 4 * A * C) if abs(denom₊) ≥ abs(denom₋) - xᵢ₊₁ = xᵢ - (xᵢ - xᵢ₋₁)*2*C/denom₊ + xᵢ₊₁ = xᵢ - (xᵢ - xᵢ₋₁) * 2 * C / denom₊ else - xᵢ₊₁ = xᵢ - (xᵢ - xᵢ₋₁)*2*C/denom₋ + xᵢ₊₁ = xᵢ - (xᵢ - xᵢ₋₁) * 2 * C / denom₋ end fxᵢ₊₁ = f(xᵢ₊₁) @@ -52,8 +52,8 @@ function CommonSolve.solve(prob::IntervalNonlinearProblem, alg::Muller, args...; # Termination Check if abstol ≥ abs(fxᵢ₊₁) return SciMLBase.build_solution(prob, alg, xᵢ₊₁, fxᵢ₊₁; - retcode = ReturnCode.Success, - left = xᵢ₊₁, right = xᵢ₊₁) + retcode = ReturnCode.Success, + left = xᵢ₊₁, right = xᵢ₊₁) end xᵢ₋₂, xᵢ₋₁, xᵢ = xᵢ₋₁, xᵢ, xᵢ₊₁ @@ -61,6 +61,6 @@ function CommonSolve.solve(prob::IntervalNonlinearProblem, alg::Muller, args...; end return SciMLBase.build_solution(prob, alg, xᵢ₊₁, fxᵢ₊₁; - retcode = ReturnCode.MaxIters, - left = xᵢ₊₁, right = xᵢ₊₁) + retcode = ReturnCode.MaxIters, + left = xᵢ₊₁, right = xᵢ₊₁) end diff --git a/lib/BracketingNonlinearSolve/test/muller_tests.jl b/lib/BracketingNonlinearSolve/test/muller_tests.jl index f4800b9d4..472e1ec7d 100644 --- a/lib/BracketingNonlinearSolve/test/muller_tests.jl +++ b/lib/BracketingNonlinearSolve/test/muller_tests.jl @@ -1,7 +1,7 @@ @testitem "Muller" begin f(u, p) = u^2 - p g(u, p) = sin(u) - h(u, p) = exp(-u)*sin(u) + h(u, p) = exp(-u) * sin(u) i(u, p) = u^3 - 1 @testset "Quadratic function" begin @@ -30,7 +30,7 @@ prob = IntervalNonlinearProblem{false}(g, tspan) sol = solve(prob, Muller()) - @test sol.u ≈ 2*π + @test sol.u ≈ 2 * π end @testset "Exponential-sine function" begin @@ -44,7 +44,7 @@ prob = IntervalNonlinearProblem{false}(h, tspan) sol = solve(prob, Muller()) - @test sol.u ≈ 0 atol = 1e-15 + @test sol.u≈0 atol=1e-15 tspan = (-1.0, 1.0) prob = IntervalNonlinearProblem{false}(h, tspan) @@ -54,17 +54,17 @@ end @testset "Complex roots" begin - tspan = (-1.0, 1.0*im) + tspan = (-1.0, 1.0 * im) prob = IntervalNonlinearProblem{false}(i, tspan) sol = solve(prob, Muller()) - @test sol.u ≈ (-1 + √3*im)/2 + @test sol.u ≈ (-1 + √3 * im) / 2 - tspan = (-1.0, -1.0*im) + tspan = (-1.0, -1.0 * im) prob = IntervalNonlinearProblem{false}(i, tspan) sol = solve(prob, Muller()) - @test sol.u ≈ (-1 - √3*im)/2 + @test sol.u ≈ (-1 - √3 * im) / 2 end @testset "Middle" begin @@ -87,10 +87,10 @@ @test sol.u ≈ -π - tspan = (-1.0, 1.0*im) + tspan = (-1.0, 1.0 * im) prob = IntervalNonlinearProblem{false}(i, tspan) sol = solve(prob, Muller(0.0)) - @test sol.u ≈ (-1 + √3*im)/2 + @test sol.u ≈ (-1 + √3 * im) / 2 end end diff --git a/lib/BracketingNonlinearSolve/test/rootfind_tests.jl b/lib/BracketingNonlinearSolve/test/rootfind_tests.jl index e8666a8c1..e32c37df0 100644 --- a/lib/BracketingNonlinearSolve/test/rootfind_tests.jl +++ b/lib/BracketingNonlinearSolve/test/rootfind_tests.jl @@ -7,7 +7,8 @@ end @testitem "Interval Nonlinear Problems" setup=[RootfindingTestSnippet] tags=[:core] begin using ForwardDiff - @testset for alg in (Alefeld(), Bisection(), Brent(), Falsi(), ITP(), Muller(), Ridder(), nothing) + @testset for alg in ( + Alefeld(), Bisection(), Brent(), Falsi(), ITP(), Muller(), Ridder(), nothing) tspan = (1.0, 20.0) function g(p) @@ -76,7 +77,8 @@ end end @testitem "Flipped Signs and Reversed Tspan" setup=[RootfindingTestSnippet] tags=[:core] begin - @testset for alg in (Alefeld(), Bisection(), Brent(), Falsi(), ITP(), Muller(), Ridder(), nothing) + @testset for alg in ( + Alefeld(), Bisection(), Brent(), Falsi(), ITP(), Muller(), Ridder(), nothing) f1(u, p) = u * u - p f2(u, p) = p - u * u diff --git a/lib/NonlinearSolveFirstOrder/Project.toml b/lib/NonlinearSolveFirstOrder/Project.toml index 19aaffaa5..9705ec183 100644 --- a/lib/NonlinearSolveFirstOrder/Project.toml +++ b/lib/NonlinearSolveFirstOrder/Project.toml @@ -23,6 +23,9 @@ SciMLJacobianOperators = "19f34311-ddf3-4b8b-af20-060888a46c0e" Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" +[sources] +NonlinearSolveBase = {path = "../NonlinearSolveBase"} + [compat] ADTypes = "1.9.0" Aqua = "0.8" diff --git a/lib/NonlinearSolveHomotopyContinuation/Project.toml b/lib/NonlinearSolveHomotopyContinuation/Project.toml index 700b9f2ee..b617b852b 100644 --- a/lib/NonlinearSolveHomotopyContinuation/Project.toml +++ b/lib/NonlinearSolveHomotopyContinuation/Project.toml @@ -16,6 +16,9 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5" TaylorDiff = "b36ab563-344f-407b-a36a-4f200bebf99c" +[sources] +NonlinearSolveBase = {path = "../NonlinearSolveBase"} + [compat] ADTypes = "1.11.0" Aqua = "0.8" diff --git a/lib/NonlinearSolveQuasiNewton/Project.toml b/lib/NonlinearSolveQuasiNewton/Project.toml index 3f81b7123..d00cbe49c 100644 --- a/lib/NonlinearSolveQuasiNewton/Project.toml +++ b/lib/NonlinearSolveQuasiNewton/Project.toml @@ -18,6 +18,9 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961" StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" +[sources] +NonlinearSolveBase = {path = "../NonlinearSolveBase"} + [weakdeps] ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" diff --git a/lib/NonlinearSolveSpectralMethods/Project.toml b/lib/NonlinearSolveSpectralMethods/Project.toml index 53f568bc0..fe355b4d0 100644 --- a/lib/NonlinearSolveSpectralMethods/Project.toml +++ b/lib/NonlinearSolveSpectralMethods/Project.toml @@ -14,6 +14,9 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" +[sources] +NonlinearSolveBase = {path = "../NonlinearSolveBase"} + [weakdeps] ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" diff --git a/lib/SimpleNonlinearSolve/Project.toml b/lib/SimpleNonlinearSolve/Project.toml index 199085937..ca6082bf9 100644 --- a/lib/SimpleNonlinearSolve/Project.toml +++ b/lib/SimpleNonlinearSolve/Project.toml @@ -23,6 +23,10 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" +[sources] +BracketingNonlinearSolve = {path = "../BracketingNonlinearSolve"} +NonlinearSolveBase = {path = "../NonlinearSolveBase"} + [weakdeps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" diff --git a/lib/SimpleNonlinearSolve/test/core/forward_diff_tests.jl b/lib/SimpleNonlinearSolve/test/core/forward_diff_tests.jl index a857e7a17..68a5d6ec0 100644 --- a/lib/SimpleNonlinearSolve/test/core/forward_diff_tests.jl +++ b/lib/SimpleNonlinearSolve/test/core/forward_diff_tests.jl @@ -14,7 +14,7 @@ jacobian_f(u, p::Number) = one.(u) .* (1 / (2 * √p)) jacobian_f(u, p::AbstractArray) = diagm(vec(@. 1 / (2 * √p))) - @testset "#(nameof(typeof(alg)))" for alg in ( + @testset "$(nameof(typeof(alg)))" for alg in ( SimpleNewtonRaphson(), SimpleTrustRegion(), SimpleTrustRegion(; nlsolve_update_rule = Val(true)),