Skip to content

Commit dac2c72

Browse files
committed
Minor fixes
1 parent 94f6f8d commit dac2c72

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

src/slopes.jl

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ import Base: +, -, *, /, ^, sqrt, exp, log, sin, cos, tan, asin, acos, atan
44
import IntervalArithmetic: mid, interval
55

66
function slope(f::Function, x::Interval, c::Number)
7-
try
8-
f(slope_var(x, c)).s
9-
catch y
10-
if isa(y, MethodError)
11-
ForwardDiff.derivative(f, x)
12-
end
13-
end
7+
f(slope_var(x, c)).s
148
end
159

1610
struct Slope{T}
17-
x::Interval{T}
18-
c::Interval{T}
19-
s::Interval{T}
11+
x::Interval{T} # Interval on which slope is evaluated
12+
c::Interval{T} # Point about which slope is evaluated (Interval to get bounded rounding errors)
13+
s::Interval{T} # Variable which propogates the slope information
2014
end
2115

2216
Slope(c) = Slope(c, c, 0)

test/slopes.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ end
1212
@testset "Automatic slope expansion" begin
1313
for T in [Float64, BigFloat]
1414
s = interval(T(0.75), T(1.75))
15-
rts = Slopes{T}[]
16-
push!(rts, Slopes(x->((x + sin(x)) * exp(-x^2)), s, mid(s), interval(T(-2.8), T(0.1))))
17-
push!(rts, Slopes(x->(x^4 - 10x^3 + 35x^2 - 50x + 24), s, mid(s), interval(T(-44), T(38.5))))
18-
push!(rts, Slopes(x->((log(x + 1.25) - 0.84x) ^ 2), s, mid(s), interval(T(-0.16), T(0.44))))
19-
push!(rts, Slopes(x->(0.02x^2 - 0.03exp(-(20(x - 0.875))^2)), s, mid(s), interval(T(0.03), T(0.33))))
20-
push!(rts, Slopes(x->(exp(x^2)), s, mid(s), interval(T(6.03), T(33.23))))
21-
push!(rts, Slopes(x->(x^4 - 12x^3 + 47x^2 - 60x - 20exp(-x)), s, mid(s), interval(T(-39), T(65.56))))
22-
push!(rts, Slopes(x->(x^6 - 15x^4 + 27x^2 + 250), s, mid(s), interval(T(-146.9), T(67.1))))
23-
push!(rts, Slopes(x->(atan(cos(tan(x)))), s, mid(s), interval(T(1), T(2))))
24-
push!(rts, Slopes(x->(asin(cos(acos(sin(x))))), s, mid(s), interval(T(1.36), T(∞))))
15+
example = Slopes{T}[]
16+
push!(example, Slopes(x->((x + sin(x)) * exp(-x^2)), s, mid(s), interval(T(-2.8), T(0.1))))
17+
push!(example, Slopes(x->(x^4 - 10x^3 + 35x^2 - 50x + 24), s, mid(s), interval(T(-44), T(38.5))))
18+
push!(example, Slopes(x->((log(x + 1.25) - 0.84x) ^ 2), s, mid(s), interval(T(-0.16), T(0.44))))
19+
push!(example, Slopes(x->(0.02x^2 - 0.03exp(-(20(x - 0.875))^2)), s, mid(s), interval(T(0.03), T(0.33))))
20+
push!(example, Slopes(x->(exp(x^2)), s, mid(s), interval(T(6.03), T(33.23))))
21+
push!(example, Slopes(x->(x^4 - 12x^3 + 47x^2 - 60x - 20exp(-x)), s, mid(s), interval(T(-39), T(65.56))))
22+
push!(example, Slopes(x->(x^6 - 15x^4 + 27x^2 + 250), s, mid(s), interval(T(-146.9), T(67.1))))
23+
push!(example, Slopes(x->(atan(cos(tan(x)))), s, mid(s), interval(T(1), T(2))))
24+
push!(example, Slopes(x->(asin(cos(acos(sin(x))))), s, mid(s), interval(T(1.36), T(∞))))
2525

26-
for i in 1:length(rts)
27-
@test slope(rts[i].f, rts[i].x, rts[i].c) rts[i].sol
26+
for i in 1:length(example)
27+
@test slope(example[i].f, example[i].x, example[i].c) example[i].sol
2828
end
2929
end
3030
end

0 commit comments

Comments
 (0)