Skip to content

Commit

Permalink
Fix tests and add AD tests for NewtonRaphson and Falsi
Browse files Browse the repository at this point in the history
  • Loading branch information
YingboMa committed Nov 20, 2020
1 parent 4542543 commit 5cacdb8
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,26 @@ end

f, u0 = (u, p) -> p[1] * u * u - p[2], (1.0, 100.0)
t = (p) -> [sqrt(p[2] / p[1])]
g = function (p)
probN = NonlinearProblem{false}(f, u0, p)
sol = solve(probN, Bisection())
return [sol.left]
p = [0.9, 50.0]
for alg in [Bisection(), Falsi()]
global g, p
g = function (p)
probN = NonlinearProblem{false}(f, u0, p)
sol = solve(probN, Bisection())
return [sol.left]
end

@test g(p) [sqrt(p[2] / p[1])]
@test ForwardDiff.jacobian(g, p) ForwardDiff.jacobian(t, p)
end

for p1 in 1.0:1.0:100.0
for p2 in 1.0:1.0:100.0
p = [p1, p2]
@show p
@test g(p) [sqrt(p[2] / p[1])]
@test ForwardDiff.jacobian(g, p) ForwardDiff.jacobian(t, p)
end
gnewton = function (p)
probN = NonlinearProblem{false}(f, 0.5, p)
sol = solve(probN, NewtonRaphson())
return [sol.u]
end
@test gnewton(p) [sqrt(p[2] / p[1])]
@test ForwardDiff.jacobian(gnewton, p) ForwardDiff.jacobian(t, p)

# Error Checks

Expand Down

0 comments on commit 5cacdb8

Please sign in to comment.