|
1 | 1 | # 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 |
4 | 4 |
|
5 | 5 | 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 |
7 | 13 | end
|
8 | 14 |
|
9 | 15 | struct SlopeType
|
|
71 | 77 | +(v::SlopeType, u::Union{Interval, Real}) = u + v
|
72 | 78 |
|
73 | 79 | -(v::SlopeType, u::Union{Interval, Real}) = u - v
|
| 80 | +-(u::SlopeType) = u * -1 |
74 | 81 |
|
75 | 82 | *(v::SlopeType, u::Union{Interval, Real}) = u * v
|
76 | 83 |
|
@@ -148,3 +155,45 @@ function log(u::SlopeType)
|
148 | 155 | end
|
149 | 156 | SlopeType(hx, hc, h1 * u.fs)
|
150 | 157 | 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