1
1
using IntervalArithmetic, IntervalRootFinding
2
- using ForwardDiff
2
+ using ForwardDiff, StaticArrays
3
3
using Base. Test
4
4
5
5
struct Slopes{T}
@@ -9,39 +9,68 @@ struct Slopes{T}
9
9
sol:: Interval{T}
10
10
end
11
11
12
- @testset " Automatic slope expansion(Float64)" begin
12
+ @testset " Automatic slope expansion" begin
13
+ for T in [Float64, BigFloat]
14
+ 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 - 10 x^ 3 + 35 x^ 2 - 50 x + 24 ), s, mid (s), interval (T (- 44 ), T (38.5 ))))
18
+ push! (rts, Slopes (x-> ((log (x + 1.25 ) - 0.84 x) ^ 2 ), s, mid (s), interval (T (- 0.16 ), T (0.44 ))))
19
+ push! (rts, Slopes (x-> (0.02 x^ 2 - 0.03 exp (- (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 - 12 x^ 3 + 47 x^ 2 - 60 x - 20 exp (- x)), s, mid (s), interval (T (- 39 ), T (65.56 ))))
22
+ push! (rts, Slopes (x-> (x^ 6 - 15 x^ 4 + 27 x^ 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 (∞))))
13
25
14
- s = interval (0.75 , 1.75 )
15
- rts = Slopes{Float64}[]
16
- push! (rts, Slopes (x-> ((x + sin (x)) * exp (- x^ 2 )), s, mid (s), interval (- 2.8 , 0.1 )))
17
- push! (rts, Slopes (x-> (x^ 4 - 10 x^ 3 + 35 x^ 2 - 50 x + 24 ), s, mid (s), interval (- 44 , 38.5 )))
18
- push! (rts, Slopes (x-> ((log (x + 1.25 ) - 0.84 x) ^ 2 ), s, mid (s), interval (- 0.16 , 0.44 )))
19
- push! (rts, Slopes (x-> (0.02 x^ 2 - 0.03 exp (- (20 (x - 0.875 ))^ 2 )), s, mid (s), interval (0.03 , 0.33 )))
20
- push! (rts, Slopes (x-> (exp (x^ 2 )), s, mid (s), interval (6.03 , 33.23 )))
21
- push! (rts, Slopes (x-> (x^ 4 - 12 x^ 3 + 47 x^ 2 - 60 x - 20 exp (- x)), s, mid (s), interval (- 39 , 65.56 )))
22
- push! (rts, Slopes (x-> (x^ 6 - 15 x^ 4 + 27 x^ 2 + 250 ), s, mid (s), interval (- 146.9 , 67.1 )))
23
- push! (rts, Slopes (x-> (atan (cos (tan (x)))), s, mid (s), interval (1 , 2 )))
24
- push! (rts, Slopes (x-> (asin (cos (acos (sin (x))))), s, mid (s), interval (1.36 , ∞)))
25
-
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 (rts)
27
+ @test slope (rts[i]. f, rts[i]. x, rts[i]. c) ⊆ rts[i]. sol
28
+ end
28
29
end
29
30
end
30
31
31
- @testset " Automatic slope expansion(BigFloat)" begin
32
- s = interval (BigFloat (0.75 ), BigFloat (1.75 ))
33
- rts = Slopes{BigFloat}[]
34
- push! (rts, Slopes (x-> ((x + sin (x)) * exp (- x^ 2 )), s, mid (s), interval (BigFloat (- 2.8 ), BigFloat (0.1 ))))
35
- push! (rts, Slopes (x-> (x^ 4 - 10 x^ 3 + 35 x^ 2 - 50 x + 24 ), s, mid (s), interval (BigFloat (- 44 ), BigFloat (38.5 ))))
36
- push! (rts, Slopes (x-> ((log (x + 1.25 ) - 0.84 x) ^ 2 ), s, mid (s), interval (BigFloat (- 0.16 ), BigFloat (0.44 ))))
37
- push! (rts, Slopes (x-> (0.02 x^ 2 - 0.03 exp (- (20 (x - 0.875 ))^ 2 )), s, mid (s), interval (BigFloat (0.03 ), BigFloat (0.33 ))))
38
- push! (rts, Slopes (x-> (exp (x^ 2 )), s, mid (s), interval (BigFloat (6.03 ), BigFloat (33.23 ))))
39
- push! (rts, Slopes (x-> (x^ 4 - 12 x^ 3 + 47 x^ 2 - 60 x - 20 exp (- x)), s, mid (s), interval (BigFloat (- 39 ), BigFloat (65.56 ))))
40
- push! (rts, Slopes (x-> (x^ 6 - 15 x^ 4 + 27 x^ 2 + 250 ), s, mid (s), interval (BigFloat (- 146.9 ), BigFloat (67.1 ))))
41
- push! (rts, Slopes (x-> (atan (cos (tan (x)))), s, mid (s), interval (BigFloat (1 ), BigFloat (2 ))))
42
- push! (rts, Slopes (x-> (asin (cos (acos (sin (x))))), s, mid (s), interval (BigFloat (1.36 ), BigFloat (∞))))
32
+ struct SlopesMulti
33
+ f:: Function
34
+ x:: IntervalBox
35
+ c:: Vector
36
+ sol:: Matrix{Interval}
37
+ end
38
+
39
+ @testset " Multidim slope expansion" begin
40
+
41
+ rts = SlopesMulti[]
42
+ f (x, y) = SVector (x^ 2 + y^ 2 - 1 , y - 2 x)
43
+ f (X) = f (X... )
44
+ X = (- 6 .. 6 ) × (- 6 .. 6 )
45
+ c = [0.0 , 0.0 ]
46
+ push! (rts, SlopesMulti (f, X, c, [- 6 .. 6 - 6 .. 6 ; - 2 .. - 2 1 .. 1 ]))
47
+
48
+ function g (x)
49
+ (x1, x2, x3) = x
50
+ SVector ( x1^ 2 + x2^ 2 + x3^ 2 - 1 ,
51
+ x1^ 2 + x3^ 2 - 0.25 ,
52
+ x1^ 2 + x2^ 2 - 4 x3
53
+ )
54
+ end
55
+
56
+ X = (- 5 .. 5 )
57
+ XX = IntervalBox (X, 3 )
58
+ cc = [0.0 , 0.0 , 0.0 ]
59
+ push! (rts, SlopesMulti (g, XX, cc, [- 5 .. 5 - 5 .. 5 - 5 .. 5 ; - 5 .. 5 0 .. 0 - 5 .. 5 ; - 5 .. 5 - 5 .. 5 - 4 .. - 4 ]))
60
+ function h (x)
61
+ (x1, x2, x3) = x
62
+ SVector ( x1 + x2^ 2 + x3^ 2 - 1 ,
63
+ x1^ 2 + x3 - 0.25 ,
64
+ x1^ 2 + x2 - 4 x3
65
+ )
66
+ end
67
+
68
+ XXX = IntervalBox (1 .. 5 , 2 .. 6 , - 3 .. 7 )
69
+ ccc = [3.0 , 4.0 , 2.0 ]
70
+ push! (rts, SlopesMulti (h, XXX, ccc, [1 .. 1 6 .. 10 - 1 .. 9 ; 4 .. 8 0 .. 0 1 .. 1 ; 4 .. 8 1 .. 1 - 4 .. - 4 ]))
43
71
44
72
for i in 1 : length (rts)
45
- @test slope (rts[i]. f, rts[i]. x, rts[i]. c) ⊆ rts[i]. sol
73
+ @test slope (rts[i]. f, rts[i]. x, rts[i]. c) == rts[i]. sol
46
74
end
75
+
47
76
end
0 commit comments