Skip to content

Commit 1098b35

Browse files
authored
Merge pull request #13 from JuliaComputing/myb/fix
Fix Newton with finite diff
2 parents e88ed56 + a0beb00 commit 1098b35

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Diff for: src/jacobian.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function jacobian(f, x, solver)
3232
if alg_autodiff(solver.alg)
3333
J = ForwardDiff.jacobian(f, x)
3434
else
35-
J = FiniteDiff.finite_difference_derivative(f, x, solver.alg.diff_type, eltype(x))
35+
J = FiniteDiff.finite_difference_jacobian(f, x, solver.alg.diff_type, eltype(x))
3636
end
3737
return J
3838
end

Diff for: test/runtests.jl

+10-8
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,16 @@ probN = NonlinearProblem(f, u0)
102102
@test solve(probN, NewtonRaphson(;autodiff=false)).u[end] sqrt(2.0)
103103
@test solve(probN, NewtonRaphson(;autodiff=false); immutable = false).u[end] sqrt(2.0)
104104

105-
f, u0 = (u, p) -> u .* u .- 2.0, 1.0
106-
probN = NonlinearProblem(f, u0)
107-
108-
@test solve(probN, NewtonRaphson()).u sqrt(2.0)
109-
@test solve(probN, NewtonRaphson(); immutable = false).u sqrt(2.0)
110-
@test solve(probN, NewtonRaphson(;autodiff=false)).u sqrt(2.0)
111-
@test solve(probN, NewtonRaphson(;autodiff=false); immutable = false).u sqrt(2.0)
112-
105+
for u0 in [1.0, [1, 1.0]]
106+
f = (u, p) -> u .* u .- 2.0
107+
probN = NonlinearProblem(f, u0)
108+
sol = sqrt(2) * u0
109+
110+
@test solve(probN, NewtonRaphson()).u sol
111+
@test solve(probN, NewtonRaphson(); immutable = false).u sol
112+
@test solve(probN, NewtonRaphson(;autodiff=false)).u sol
113+
@test solve(probN, NewtonRaphson(;autodiff=false); immutable = false).u sol
114+
end
113115

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

0 commit comments

Comments
 (0)