Skip to content

Commit e994826

Browse files
committed
rectangle_rule was erron incl the final endpoint. Bump to 0.2.1
1 parent adb1e4e commit e994826

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FunctionIntegrator"
22
uuid = "7685536e-2581-4f83-bef1-2ba363c9cb91"
33
authors = ["Brenton Horne <[email protected]>"]
4-
version = "0.2.0"
4+
version = "0.2.1"
55

66
[deps]
77
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"

src/Rectangle.jl

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@ numerically approximates:
55
66
``\\displaystyle\\int_a^b f(x) dx``
77
8-
using the [rectangle rule](https://en.wikipedia.org/wiki/Riemann_sum#Left_Riemann_sum) with ``N+1`` steps (including the endpoints). Whilst the type mentioned in the function definition for ``N`` is just 'Number' (as opposed to 'Integer'), this is just so that scientific notation can be used to define it (as scientific notation gives the type 'Float64'), an error message will be printed if it is not a positive integer.
8+
using the [rectangle rule](https://en.wikipedia.org/wiki/Riemann_sum#Left_Riemann_sum) with ``N`` gridpoint values. Whilst the type mentioned in the function definition for ``N`` is just 'Number' (as opposed to 'Integer'), this is just so that scientific notation can be used to define it (as scientific notation gives the type 'Float64'); an error message will be printed if it is not a positive integer.
99
"""
1010
function rectangle_rule(f::Function, N::Number, a::Number, b::Number)
1111
N = convert(Int64, N);
1212
h = (b-a)/N;
1313
y = 0;
1414
x = a;
15-
for i=1:N+1
15+
for i=1:N
1616
y += h*f(x)
17-
if i < N+1
18-
x = x + h;
19-
end
17+
x = x + h;
2018
end
2119
return y
2220
end

test/logoverx.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ printstyled("Integrating log(x)/x from 1 to e and comparing the result to the an
1717
printstyled("Running: radau_quadrature\n"; color = :magenta)
1818
@time @test radau_quadrature(x -> log.(x).*x.^(-1), 8, 1, exp(1)) 0.5
1919
printstyled("Running: rectangle_rule\n"; color = :magenta)
20-
@time @test rectangle_rule(x -> log.(x).*x.^(-1), 4.38e7, 1, exp(1)) 0.5
20+
@time @test rectangle_rule(x -> log.(x).*x.^(-1), 4.3800001e7, 1, exp(1)) 0.5
2121
printstyled("Running: simpsons_rule\n"; color = :magenta)
2222
@time @test simpsons_rule(x -> log.(x).*x.^(-1), 100, 1, exp(1)) 0.5
2323
printstyled("Running: trapezoidal_rule\n"; color = :magenta)

0 commit comments

Comments
 (0)