Skip to content

Commit

Permalink
Merge pull request #13 from JuliaComputing/myb/fix
Browse files Browse the repository at this point in the history
Fix Newton with finite diff
  • Loading branch information
YingboMa authored Nov 22, 2020
2 parents e88ed56 + a0beb00 commit 1098b35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/jacobian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function jacobian(f, x, solver)
if alg_autodiff(solver.alg)
J = ForwardDiff.jacobian(f, x)
else
J = FiniteDiff.finite_difference_derivative(f, x, solver.alg.diff_type, eltype(x))
J = FiniteDiff.finite_difference_jacobian(f, x, solver.alg.diff_type, eltype(x))
end
return J
end
Expand Down
18 changes: 10 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ probN = NonlinearProblem(f, u0)
@test solve(probN, NewtonRaphson(;autodiff=false)).u[end] sqrt(2.0)
@test solve(probN, NewtonRaphson(;autodiff=false); immutable = false).u[end] sqrt(2.0)

f, u0 = (u, p) -> u .* u .- 2.0, 1.0
probN = NonlinearProblem(f, u0)

@test solve(probN, NewtonRaphson()).u sqrt(2.0)
@test solve(probN, NewtonRaphson(); immutable = false).u sqrt(2.0)
@test solve(probN, NewtonRaphson(;autodiff=false)).u sqrt(2.0)
@test solve(probN, NewtonRaphson(;autodiff=false); immutable = false).u sqrt(2.0)

for u0 in [1.0, [1, 1.0]]
f = (u, p) -> u .* u .- 2.0
probN = NonlinearProblem(f, u0)
sol = sqrt(2) * u0

@test solve(probN, NewtonRaphson()).u sol
@test solve(probN, NewtonRaphson(); immutable = false).u sol
@test solve(probN, NewtonRaphson(;autodiff=false)).u sol
@test solve(probN, NewtonRaphson(;autodiff=false); immutable = false).u sol
end

# Bisection Tests
f, u0 = (u, p) -> u .* u .- 2.0, (1.0, 2.0)
Expand Down

0 comments on commit 1098b35

Please sign in to comment.