Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit b663ad5

Browse files
committed
more tests
1 parent e44bab2 commit b663ad5

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/alefeld.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem,
1818
c = a - (b - a) / (f(b) - f(a)) * f(a)
1919

2020
fc = f(c)
21-
if iszero(fc)
21+
(a == c || b == c) &&
22+
return SciMLBase.build_solution(prob, alg, c, fc;
23+
retcode = ReturnCode.FloatingPointLimit,
24+
left = a,
25+
right = b)
26+
iszero(fc) &&
2227
return SciMLBase.build_solution(prob, alg, c, fc;
2328
retcode = ReturnCode.Success,
2429
left = a,
2530
right = b)
26-
end
2731
a, b, d = _bracket(f, a, b, c)
2832
e = zero(a) # Set e as 0 before iteration to avoid a non-value f(e)
2933

test/basictests.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ for p in 1.1:0.1:100.0
222222
@test ForwardDiff.derivative(g, p) 1 / (2 * sqrt(p))
223223
end
224224

225+
f, tspan = (u, p) -> p[1] * u * u - p[2], (1.0, 100.0)
226+
t = (p) -> [sqrt(p[2] / p[1])]
227+
p = [0.9, 50.0]
228+
g = function (p)
229+
probN = IntervalNonlinearProblem{false}(f, tspan, p)
230+
sol = solve(probN, Alefeld())
231+
return [sol.u]
232+
end
233+
234+
@test g(p) [sqrt(p[2] / p[1])]
235+
@test ForwardDiff.jacobian(g, p) ForwardDiff.jacobian(t, p)
236+
225237
f, tspan = (u, p) -> p[1] * u * u - p[2], (1.0, 100.0)
226238
t = (p) -> [sqrt(p[2] / p[1])]
227239
p = [0.9, 50.0]
@@ -288,6 +300,7 @@ probB = IntervalNonlinearProblem(f, tspan)
288300
sol = solve(probB, Falsi())
289301
@test sol.left sqrt(2.0)
290302

303+
# Bisection
291304
sol = solve(probB, Bisection())
292305
@test sol.left sqrt(2.0)
293306

@@ -315,6 +328,18 @@ probB = IntervalNonlinearProblem(f, tspan)
315328
sol = solve(probB, Brent())
316329
@test sol.left sqrt(2.0)
317330

331+
# Alefeld
332+
sol = solve(probB, Alefeld())
333+
@test sol.u sqrt(2.0)
334+
tspan = (sqrt(2.0), 10.0)
335+
probB = IntervalNonlinearProblem(f, tspan)
336+
sol = solve(probB, Alefeld())
337+
@test sol.u sqrt(2.0)
338+
tspan = (0.0, sqrt(2.0))
339+
probB = IntervalNonlinearProblem(f, tspan)
340+
sol = solve(probB, Alefeld())
341+
@test sol.u sqrt(2.0)
342+
318343
# Garuntee Tests for Bisection
319344
f = function (u, p)
320345
if u < 2.0

0 commit comments

Comments
 (0)