Skip to content

Commit d975c04

Browse files
committed
Fix direction bug in falsi
1 parent f04850b commit d975c04

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/scalar.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function solve(prob::NonlinearProblem, ::Falsi, args...; maxiters = 1000, kwargs
128128
end
129129
mid = (fr * left - fl * right) / (fr - fl)
130130
for i in 1:10
131-
mid = max(left, prevfloat_tdir(mid, prob.u0...))
131+
mid = max_tdir(left, prevfloat_tdir(mid, prob.u0...), prob.u0...)
132132
end
133133
if mid == right || mid == left
134134
break

src/utils.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ function nextfloat_tdir(x::T, x0::T, x1::T)::T where {T}
221221
x1 > x0 ? nextfloat(x) : prevfloat(x)
222222
end
223223

224+
function max_tdir(a::T, b::T, x0::T1, x1::T1)::T where {T, T1}
225+
x1 > x0 ? max(a, b) : min(a, b)
226+
end
227+
224228
alg_autodiff(alg::AbstractNewtonAlgorithm{CS,AD}) where {CS,AD} = AD
225229
alg_autodiff(alg) = false
226230

0 commit comments

Comments
 (0)