From 0f2e774a8b55f3841d28c691deb5869e835e5eb2 Mon Sep 17 00:00:00 2001 From: BriceonWiley Date: Sat, 19 Dec 2020 22:17:40 -0600 Subject: [PATCH] updated to account for autodiff=false --- src/scalar.jl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/scalar.jl b/src/scalar.jl index dda7329bd..66ab6d4b5 100644 --- a/src/scalar.jl +++ b/src/scalar.jl @@ -1,4 +1,4 @@ -function solve(prob::NonlinearProblem{<:Number}, ::NewtonRaphson, args...; xatol = nothing, xrtol = nothing, maxiters = 1000, kwargs...) +function solve(prob::NonlinearProblem{<:Number}, alg::NewtonRaphson, args...; xatol = nothing, xrtol = nothing, maxiters = 1000, kwargs...) f = Base.Fix2(prob.f, prob.p) x = float(prob.u0) T = typeof(x) @@ -7,7 +7,12 @@ function solve(prob::NonlinearProblem{<:Number}, ::NewtonRaphson, args...; xatol xo = oftype(x, Inf) for i in 1:maxiters - fx, dfx = value_derivative(f, x) + if alg_autodiff(alg) + fx, dfx = value_derivative(f, x) + else + fx = f(x) + dfx = FiniteDiff.finite_difference_derivative(f, x, alg.diff_type, eltype(x), fx) + end iszero(fx) && return NewtonSolution(x, DEFAULT) Δx = dfx \ fx x -= Δx