Skip to content

Commit

Permalink
Merge pull request #21 from BriceonWiley/finite_scalar
Browse files Browse the repository at this point in the history
updated to account for autodiff=false
  • Loading branch information
ChrisRackauckas authored Dec 20, 2020
2 parents 8ccca30 + 0f2e774 commit 214bd4d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/scalar.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 214bd4d

Please sign in to comment.