Add some commentary to Gauss-Seidel function

This commit is contained in:
sheaf 2024-04-24 01:30:24 +02:00
parent a59f1695fb
commit 32ce7c38bb
2 changed files with 8 additions and 2 deletions

View file

@ -115,7 +115,7 @@ bisect x@( 𝕀 x_inf x_sup )
where x_mid = midpoint x
infixl 6
() :: ( Ring a, Ord a ) => 𝕀 a -> 𝕀 a -> 𝕀 a
() :: ( AbelianGroup a, Ord a ) => 𝕀 a -> 𝕀 a -> 𝕀 a
() a@( 𝕀 lo1 hi1 ) b@( 𝕀 lo2 hi2 )
| width a >= width b
= 𝕀 ( lo1 - lo2 ) ( hi1 - hi2 )

View file

@ -202,7 +202,13 @@ gaussSeidelStep
-> [ ( T ( 𝕀 n ), Bool ) ]
gaussSeidelStep as b ( T x0 ) = coerce $
forEachCoord @n ( x0, True ) $ \ i ( x, contraction ) -> do
-- x_i' = ( b_i - sum { j /= i } a_ij * x_j ) / a_ii
-- For each i, we have an equation: sum_j a_ij * x_j = b_i
--
-- Re-arrange this with x_i on the left to get an iteration:
-- x_i' = ( b_i - sum { j /= i } a_ij * x_j ) / a_ii
--
-- We perform each iteration in turn (for i = 1, ..., n),
-- **using the latest updated value of each x_j** in each iteration.
let s = b `index` i - sum [ ( as ! j ) `index` i * x `index` j
| j <- toList ( universe @n ), j /= i ]
x_i = x `index` i