Skip to content

Commit

Permalink
Merge pull request #20 from JuliaComputing/dirfix
Browse files Browse the repository at this point in the history
Fix direction bug in Falsi
  • Loading branch information
ChrisRackauckas authored Dec 9, 2020
2 parents f04850b + d975c04 commit 8ccca30
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/scalar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function solve(prob::NonlinearProblem, ::Falsi, args...; maxiters = 1000, kwargs
end
mid = (fr * left - fl * right) / (fr - fl)
for i in 1:10
mid = max(left, prevfloat_tdir(mid, prob.u0...))
mid = max_tdir(left, prevfloat_tdir(mid, prob.u0...), prob.u0...)
end
if mid == right || mid == left
break
Expand Down
4 changes: 4 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ function nextfloat_tdir(x::T, x0::T, x1::T)::T where {T}
x1 > x0 ? nextfloat(x) : prevfloat(x)
end

function max_tdir(a::T, b::T, x0::T1, x1::T1)::T where {T, T1}
x1 > x0 ? max(a, b) : min(a, b)
end

alg_autodiff(alg::AbstractNewtonAlgorithm{CS,AD}) where {CS,AD} = AD
alg_autodiff(alg) = false

Expand Down

0 comments on commit 8ccca30

Please sign in to comment.