Skip to content

Commit a8fc33d

Browse files
committed
Simple doubling in N size for adaptive_simpsons_rule seems best
1 parent 485c8c6 commit a8fc33d

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/Simpson.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,7 @@ function adaptive_simpsons_rule(f::Function, a::Number, b::Number, ε::Float64=1
7979
criterion = 100*ε;
8080
while criterion >= 15*ε
8181
criterion = abs((simpsons_rule(f, N, a, (a+b)/2)+simpsons_rule(f, N, (a+b)/2, b)-simpsons_rule(f, N, a, b))/simpsons_rule(f, N, a, b));
82-
if criterion >= 15*ε
83-
# The following N adjustment comes from the error formula for Simpson's rule
84-
N = convert(Int64, round((((16*criterion)/(15*ε))^(1/4))*N));
85-
if ! iseven(N)
86-
N = N+1;
87-
end
88-
else
89-
N = 2*N;
90-
end
82+
N = 2*N;
9183
end
9284
return simpsons_rule(f, N, a, b)
9385
end

test/sinxx.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ sol_8 = 1.562225466889056293352345138804502677227824980541083456384;
88
printstyled("Integrating sin(x)/x from 0 to 100 and comparing it to the exact result.\n"; color = :red)
99
@testset "sinxx" begin
1010
printstyled("Running: adaptive_simpsons_rule with ε=1e-7\n"; color = :magenta)
11-
@time @test adaptive_simpsons_rule(sinxx, 0, 100, 1e-7) sol_8
11+
# Using 1e-7 returns and error, despite it being accurate to an absolute and
12+
# relative tolerance of 1e-7
13+
@time @test adaptive_simpsons_rule(sinxx, 0, 100, 1e-8) sol_8
1214
printstyled("Running: chebyshev_quadrature with k=1\n"; color = :magenta)
1315
@time @test chebyshev_quadrature(sinxx, 29645, 1, 0, 100) sol_8
1416
printstyled("Running: chebyshev_quadrature with k=2\n"; color = :magenta)

0 commit comments

Comments
 (0)