Skip to content

Commit

Permalink
error with e variable in a42a
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani committed Jul 2, 2015
1 parent 4f92cfe commit f5f3789
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/SOLVE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function have_bracket(f, a, b, c=(0.5)*(a+b);
throw(ConvergenceFailed("Interval [$a, $b] is not a bracket"))
end
a,b = sort([a,b])
if !(a < c < b)
if !(a <= c <= b)
throw(ConvergenceFailed("Value $c is not in interval ($a, $b)"))
end

Expand Down
9 changes: 5 additions & 4 deletions src/fzero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ function a42a(f::Function, a, b, c=(0.5)*(a+b);
try
# re-bracket and check termination
a, b, d = bracket(f, a, b, c, xtol)
ee = d
for n = 2:maxeval
# use either a cubic (if possible) or quadratic interpolation
if n > 2 && distinct(f, a, b, d, e)
c = ipzero(f, a, b, d, e)
if n > 2 && distinct(f, a, b, d, ee)
c = ipzero(f, a, b, d, ee)
else
c = newton_quadratic(f, a, b, d, 2)
end
Expand All @@ -189,9 +190,9 @@ function a42a(f::Function, a, b, c=(0.5)*(a+b);
a = ah
b = bh
d = dh
e = db
ee = db
else
e = dh
ee = dh
a, b, d = bracket(f, ah, bh, ah + (bh - ah)/2,
xtol)
end
Expand Down
1 change: 1 addition & 0 deletions test/test_fzero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Roots.fzero
# test problems from Table 1 of paper referenced in fzero.jl
# 1
@test_approx_eq fzero(x -> sin(x) - x/2, pi/2, pi) 1.89549426703398094714
@test_approx_eq Roots.a42a(x -> sin(x) - x/2, pi/2, pi) 1.89549426703398094714

# 2
function test2(x)
Expand Down

0 comments on commit f5f3789

Please sign in to comment.