1 {-
    2         Solution error computation for both Jacobi and main
    3         iterations
    4 
    5         XZ 25/2/92
    6 -}
    7 
    8 module Tol_cal (tol_cal) where
    9 
   10 import Defs
   11 import S_Array  -- not needed w/ proper module handling
   12 import Norm     -- ditto
   13 
   14 tol_cal :: [Frac_type] -> [Frac_type] -> Bool -> Frac_type
   15 tol_cal x dif jcb_itn =
   16         case (x_abs_max<small) || (x_sq_sum<small) of
   17                 True      ->
   18                         if jcb_itn
   19                         then error "Jacobi iteration: solution too small!"
   20                         else error "main iteration: solution too small!"
   21                 otherwise ->
   22                         if jcb_itn || (x_abs_max>=(1::Frac_type))
   23                         then sqrt ( sq_sum_abs_dif/x_sq_sum )
   24                         else sqrt ( sq_sum_abs_dif )
   25         where
   26         sq_sum_abs_dif = sq_sum abs_dif
   27         x_abs_max = maximum (map abs x)
   28         x_sq_sum = sq_sum x
   29         abs_dif = map abs dif
   30         sq_sum = \y -> sum (map (\x->x*x) y)