Skip to content

Commit c9f0305

Browse files
committed
Add functions which return derivative for completeness (outer bound)
1 parent 79a828f commit c9f0305

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

src/IntervalRootFinding.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export
1818
derivative, jacobian, # reexport derivative from ForwardDiff
1919
Root, is_unique,
2020
roots, find_roots,
21-
bisect, newton1d
21+
bisect, newton1d, slope
2222

2323
export isunique, root_status
2424

@@ -58,7 +58,7 @@ include("complex.jl")
5858
include("contractors.jl")
5959
include("roots.jl")
6060
include("newton1d.jl")
61-
61+
include("slopes.jl")
6262

6363

6464
gradient(f) = X -> ForwardDiff.gradient(f, SVector(X))

src/slopes.jl

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Reference : Dietmar Ratz - An Optimized Interval Slope Arithmetic and its Application
2-
using IntervalArithmetic
3-
import Base: +, -, *, /, ^, sqrt, exp, log
2+
using IntervalArithmetic, ForwardDiff
3+
import Base: +, -, *, /, ^, sqrt, exp, log, sin, cos, tan, asin, acos, atan
44

55
function slope(f::Function, x::Interval, c::Real)
6-
f(SlopeVar(x, c)).fs
6+
try
7+
f(SlopeVar(x, c)).fs
8+
catch y
9+
if isa(y, MethodError)
10+
ForwardDiff.derivative(f, x)
11+
end
12+
end
713
end
814

915
struct SlopeType
@@ -71,6 +77,7 @@ end
7177
+(v::SlopeType, u::Union{Interval, Real}) = u + v
7278

7379
-(v::SlopeType, u::Union{Interval, Real}) = u - v
80+
-(u::SlopeType) = u * -1
7481

7582
*(v::SlopeType, u::Union{Interval, Real}) = u * v
7683

@@ -148,3 +155,45 @@ function log(u::SlopeType)
148155
end
149156
SlopeType(hx, hc, h1 * u.fs)
150157
end
158+
159+
function sin(u::SlopeType) # Using derivative to upper bound the slope expansion for now
160+
hx = sin(u.fx)
161+
hc = sin(u.fc)
162+
hs = cos(u.fx)
163+
SlopeType(hx, hc, hs)
164+
end
165+
166+
function cos(u::SlopeType) # Using derivative to upper bound the slope expansion for now
167+
hx = cos(u.fx)
168+
hc = cos(u.fc)
169+
hs = -sin(u.fx)
170+
SlopeType(hx, hc, hs)
171+
end
172+
173+
function tan(u::SlopeType) # Using derivative to upper bound the slope expansion for now
174+
hx = tan(u.fx)
175+
hc = tan(u.fc)
176+
hs = (sec(u.fx)) ^ 2
177+
SlopeType(hx, hc, hs)
178+
end
179+
180+
function asin(u::SlopeType)
181+
hx = asin(u.fx)
182+
hc = asin(u.fc)
183+
hs = 1 / sqrt(1 - (u.fx ^ 2))
184+
SlopeType(hx, hc, hs)
185+
end
186+
187+
function acos(u::SlopeType)
188+
hx = acos(u.fx)
189+
hc = acos(u.fc)
190+
hs = -1 / sqrt(1 - (u.fx ^ 2))
191+
SlopeType(hx, hc, hs)
192+
end
193+
194+
function atan(u::SlopeType)
195+
hx = atan(u.fx)
196+
hc = atan(u.fc)
197+
hs = 1 / 1 + (u.fx ^ 2)
198+
SlopeType(hx, hc, hs)
199+
end

0 commit comments

Comments
 (0)