Skip to content

Commit

Permalink
catch division by zero in SecantMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
haakon-e committed Dec 19, 2024
1 parent 03af1d9 commit 7afc4be
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/RootSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ function find_zero(
x0, y0 = x1, y1
push_history!(x_history, x0, soltype)
push_history!(y_history, y0, soltype)
if abs(Δy) 2eps(y0) # catch for division by zero (machine-small Δy)
return SolutionResults(
soltype,
x0,
abs(Δx) 2eps(x0), # only declare convergence if Δx is small
y0,
i,
x_history,
y_history,
)
end
x1 -= y1 * Δx / Δy
y1 = f(x1)
if tol(x0, x1, y1)
Expand Down

0 comments on commit 7afc4be

Please sign in to comment.