Skip to content

Commit 214bd4d

Browse files
Merge pull request #21 from BriceonWiley/finite_scalar
updated to account for autodiff=false
2 parents 8ccca30 + 0f2e774 commit 214bd4d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/scalar.jl

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function solve(prob::NonlinearProblem{<:Number}, ::NewtonRaphson, args...; xatol = nothing, xrtol = nothing, maxiters = 1000, kwargs...)
1+
function solve(prob::NonlinearProblem{<:Number}, alg::NewtonRaphson, args...; xatol = nothing, xrtol = nothing, maxiters = 1000, kwargs...)
22
f = Base.Fix2(prob.f, prob.p)
33
x = float(prob.u0)
44
T = typeof(x)
@@ -7,7 +7,12 @@ function solve(prob::NonlinearProblem{<:Number}, ::NewtonRaphson, args...; xatol
77

88
xo = oftype(x, Inf)
99
for i in 1:maxiters
10-
fx, dfx = value_derivative(f, x)
10+
if alg_autodiff(alg)
11+
fx, dfx = value_derivative(f, x)
12+
else
13+
fx = f(x)
14+
dfx = FiniteDiff.finite_difference_derivative(f, x, alg.diff_type, eltype(x), fx)
15+
end
1116
iszero(fx) && return NewtonSolution(x, DEFAULT)
1217
Δx = dfx \ fx
1318
x -= Δx

0 commit comments

Comments
 (0)