1
+ using IntervalArithmetic
1
2
"""
2
3
Preconditions the matrix A and b with the inverse of mid(A)
3
4
"""
@@ -15,10 +16,6 @@ function gauss_seidel_interval(A::AbstractMatrix, b::AbstractArray; precondition
15
16
n = size (A, 1 )
16
17
x = fill (- 1e16 .. 1e16 , n)
17
18
18
- if (typeof (b) <: SArray || typeof (b) <: MArray )
19
- x = MVector {n} (x)
20
- end
21
-
22
19
gauss_seidel_interval! (x, A, b, precondition= precondition, maxiter= maxiter)
23
20
return x
24
21
end
@@ -47,148 +44,11 @@ function gauss_seidel_interval!(x::AbstractArray, A::AbstractMatrix, b::Abstract
47
44
end
48
45
x
49
46
end
50
- #
51
- # function preconditioner_static{T, N}(A::MMatrix{N, N, Interval{T}}, b::MVector{N, Interval{T}})
52
- #
53
- # Aᶜ = mid.(A)
54
- # B = inv(Aᶜ)
55
- #
56
- # return B*A, B*b
57
- #
58
- # end
59
- #
60
- #
61
- # function gauss_seidel_interval_static{T, N}(A::MMatrix{N, N, Interval{T}}, b::MVector{N, Interval{T}}; precondition=true, maxiter=100)
62
- #
63
- # n = size(A, 1)
64
- # x = @MVector fill(-1e16..1e16, n)
65
- # gauss_seidel_interval_static!(x, A, b, precondition=precondition, maxiter=maxiter)
66
- # return x
67
- # end
68
- #
69
- # """
70
- # Iteratively solves the system of interval linear
71
- # equations and returns the solution set. Uses the
72
- # Gauss-Seidel method (Hansen-Sengupta version) to solve the system.
73
- # Keyword `precondition` to turn preconditioning off.
74
- # Eldon Hansen and G. William Walster : Global Optimization Using Interval Analysis - Chapter 5 - Page 115
75
- # """
76
- # function gauss_seidel_interval_static!{T, N}(x::MVector{N, Interval{T}}, A::MMatrix{N, N, Interval{T}}, b::MVector{N, Interval{T}}; precondition=true, maxiter=100)
77
- #
78
- # precondition && ((A, b) = preconditioner_static(A, b))
79
- #
80
- # n = size(A, 1)
81
- #
82
- # for iter in 1:maxiter
83
- # for i in 1:n
84
- # Y = b[i]
85
- # for j in 1:n
86
- # (i == j) || (Y -= A[i, j] * x[j])
87
- # end
88
- # Z = extended_div(Y, A[i, i])
89
- # x[i] = hull((x[i] ∩ Z[1]), x[i] ∩ Z[2])
90
- # end
91
- # end
92
- # x
93
- # end
94
- #
95
- # function preconditioner_static1{T, N}(A::SMatrix{N, N, Interval{T}}, b::SVector{N, Interval{T}})
96
- #
97
- # Aᶜ = mid.(A)
98
- # B = inv(Aᶜ)
99
- #
100
- # return B*A, B*b
101
- #
102
- # end
103
- #
104
- #
105
- # function gauss_seidel_interval_static1{T, N}(A::SMatrix{N, N, Interval{T}}, b::SVector{N, Interval{T}}; precondition=true, maxiter=100)
106
- #
107
- # n = size(A, 1)
108
- # x = @MVector fill(-1e16..1e16, n)
109
- # gauss_seidel_interval_static1!(x, A, b, precondition=precondition, maxiter=maxiter)
110
- # return x
111
- # end
112
- #
113
- # """
114
- # Iteratively solves the system of interval linear
115
- # equations and returns the solution set. Uses the
116
- # Gauss-Seidel method (Hansen-Sengupta version) to solve the system.
117
- # Keyword `precondition` to turn preconditioning off.
118
- # Eldon Hansen and G. William Walster : Global Optimization Using Interval Analysis - Chapter 5 - Page 115
119
- # """
120
- # function gauss_seidel_interval_static1!{T, N}(x::MVector{N, Interval{T}}, A::SMatrix{N, N, Interval{T}}, b::SVector{N, Interval{T}}; precondition=true, maxiter=100)
121
- #
122
- # precondition && ((A, b) = preconditioner_static1(A, b))
123
- #
124
- # n = size(A, 1)
125
- #
126
- # for iter in 1:maxiter
127
- # for i in 1:n
128
- # Y = b[i]
129
- # for j in 1:n
130
- # (i == j) || (Y -= A[i, j] * x[j])
131
- # end
132
- # Z = extended_div(Y, A[i, i])
133
- # x[i] = hull((x[i] ∩ Z[1]), x[i] ∩ Z[2])
134
- # end
135
- # end
136
- # x
137
- # end
138
- #
139
- # function preconditioner_static2{T, N}(A::SMatrix{N, N, Interval{T}}, b::SVector{N, Interval{T}})
140
- #
141
- # Aᶜ = mid.(A)
142
- # B = inv(Aᶜ)
143
- #
144
- # return B*A, B*b
145
- #
146
- # end
147
- #
148
- #
149
- # function gauss_seidel_interval_static2{T, N}(A::SMatrix{N, N, Interval{T}}, b::SVector{N, Interval{T}}; precondition=true, maxiter=100)
150
- #
151
- # n = size(A, 1)
152
- # x = @SVector fill(-1e16..1e16, n)
153
- # x = gauss_seidel_interval_static2!(x, A, b, precondition=precondition, maxiter=maxiter)
154
- # return x
155
- # end
156
- #
157
- # """
158
- # Iteratively solves the system of interval linear
159
- # equations and returns the solution set. Uses the
160
- # Gauss-Seidel method (Hansen-Sengupta version) to solve the system.
161
- # Keyword `precondition` to turn preconditioning off.
162
- # Eldon Hansen and G. William Walster : Global Optimization Using Interval Analysis - Chapter 5 - Page 115
163
- # """
164
- # function gauss_seidel_interval_static2!{T, N}(x::SVector{N, Interval{T}}, A::SMatrix{N, N, Interval{T}}, b::SVector{N, Interval{T}}; precondition=true, maxiter=100)
165
- #
166
- # precondition && ((A, b) = preconditioner_static2(A, b))
167
- #
168
- # n = size(A, 1)
169
- #
170
- # for iter in 1:maxiter
171
- # for i in 1:n
172
- # Y = b[i]
173
- # for j in 1:n
174
- # (i == j) || (Y -= A[i, j] * x[j])
175
- # end
176
- # Z = extended_div(Y, A[i, i])
177
- # x = setindex(x, hull((x[i] ∩ Z[1]), x[i] ∩ Z[2]), i)
178
- # end
179
- # end
180
- # x
181
- # end
182
47
183
48
function gauss_seidel_contractor (A:: AbstractMatrix , b:: AbstractArray ; precondition= true , maxiter= 100 )
184
49
185
50
n = size (A, 1 )
186
51
x = fill (- 1e16 .. 1e16 , n)
187
-
188
- if (typeof (b) <: SArray || typeof (b) <: MArray )
189
- x = MVector {n} (x)
190
- end
191
-
192
52
x = gauss_seidel_contractor! (x, A, b, precondition= precondition, maxiter= maxiter)
193
53
return x
194
54
end
@@ -215,3 +75,77 @@ function gauss_seidel_contractor!(x::AbstractArray, A::AbstractMatrix, b::Abstra
215
75
end
216
76
x
217
77
end
78
+
79
+ function gauss_elimination_interval (A:: AbstractMatrix , b:: AbstractArray ; precondition= true )
80
+
81
+ n = size (A, 1 )
82
+ x = fill (- 1e16 .. 1e16 , n)
83
+
84
+ x = gauss_seidel_interval! (x, A, b, precondition= precondition)
85
+
86
+ return x
87
+ end
88
+ """
89
+ Iteratively solves the system of interval linear
90
+ equations and returns the solution set. Uses the
91
+ Gauss-Seidel method (Hansen-Sengupta version) to solve the system.
92
+ Keyword `precondition` to turn preconditioning off.
93
+ Eldon Hansen and G. William Walster : Global Optimization Using Interval Analysis - Chapter 5 - Page 115
94
+ """
95
+ function gauss_elimination_interval! (x:: AbstractArray , a:: AbstractMatrix , b:: AbstractArray ; precondition= true )
96
+
97
+ precondition && ((a, b) = preconditioner (a, b))
98
+
99
+ n = size (a, 1 )
100
+
101
+ p = zeros (x)
102
+
103
+ for i in 1 : (n- 1 )
104
+ if 0 ∈ a[i, i] # diagonal matrix is not invertible
105
+ p .= entireinterval (b[1 ])
106
+ return p .∩ x
107
+ end
108
+
109
+ for j in (i+ 1 ): n
110
+ α = a[j, i] / a[i, i]
111
+ b[j] -= α * b[i]
112
+
113
+ for k in (i+ 1 ): n
114
+ a[j, k] -= α * a[i, k]
115
+ end
116
+ end
117
+ end
118
+
119
+ for i in n: - 1 : 1
120
+ sum = 0
121
+ for j in (i+ 1 ): n
122
+ sum += a[i, j] * p[j]
123
+ end
124
+ p[i] = (b[i] - sum) / a[i, i]
125
+ end
126
+
127
+ p .∩ x
128
+ end
129
+
130
+ function gauss_elimination_interval1 (A:: AbstractMatrix , b:: AbstractArray ; precondition= true )
131
+
132
+ n = size (A, 1 )
133
+ x = fill (- 1e16 .. 1e16 , n)
134
+
135
+ x = gauss_seidel_interval! (x, A, b, precondition= precondition)
136
+
137
+ return x
138
+ end
139
+ """
140
+ Iteratively solves the system of interval linear
141
+ equations and returns the solution set. Uses the
142
+ Gauss-Seidel method (Hansen-Sengupta version) to solve the system.
143
+ Keyword `precondition` to turn preconditioning off.
144
+ Eldon Hansen and G. William Walster : Global Optimization Using Interval Analysis - Chapter 5 - Page 115
145
+ """
146
+ function gauss_elimination_interval1! (x:: AbstractArray , a:: AbstractMatrix , b:: AbstractArray ; precondition= true )
147
+
148
+ precondition && ((a, b) = preconditioner (a, b))
149
+
150
+ a \ b
151
+ end
0 commit comments