Skip to content

Commit 5cacdb8

Browse files
committed
Fix tests and add AD tests for NewtonRaphson and Falsi
1 parent 4542543 commit 5cacdb8

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

test/runtests.jl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,26 @@ end
7171

7272
f, u0 = (u, p) -> p[1] * u * u - p[2], (1.0, 100.0)
7373
t = (p) -> [sqrt(p[2] / p[1])]
74-
g = function (p)
75-
probN = NonlinearProblem{false}(f, u0, p)
76-
sol = solve(probN, Bisection())
77-
return [sol.left]
74+
p = [0.9, 50.0]
75+
for alg in [Bisection(), Falsi()]
76+
global g, p
77+
g = function (p)
78+
probN = NonlinearProblem{false}(f, u0, p)
79+
sol = solve(probN, Bisection())
80+
return [sol.left]
81+
end
82+
83+
@test g(p) [sqrt(p[2] / p[1])]
84+
@test ForwardDiff.jacobian(g, p) ForwardDiff.jacobian(t, p)
7885
end
7986

80-
for p1 in 1.0:1.0:100.0
81-
for p2 in 1.0:1.0:100.0
82-
p = [p1, p2]
83-
@show p
84-
@test g(p) [sqrt(p[2] / p[1])]
85-
@test ForwardDiff.jacobian(g, p) ForwardDiff.jacobian(t, p)
86-
end
87+
gnewton = function (p)
88+
probN = NonlinearProblem{false}(f, 0.5, p)
89+
sol = solve(probN, NewtonRaphson())
90+
return [sol.u]
8791
end
92+
@test gnewton(p) [sqrt(p[2] / p[1])]
93+
@test ForwardDiff.jacobian(gnewton, p) ForwardDiff.jacobian(t, p)
8894

8995
# Error Checks
9096

0 commit comments

Comments
 (0)