module Quant.Math.Utilities (
tdmaSolver
) where
import Control.Monad
import Control.Monad.ST
import qualified Data.Vector.Mutable as M
import qualified Data.Vector as V
tdmaSolver :: (Fractional a, Ord a) => [a] -> [a] -> [a] -> [a] -> [a]
tdmaSolver aL bL cL dL = V.toList $
let [a,b,c,d] = map V.fromList [aL,bL,cL,dL] in
runST $ do
c' <- V.thaw c
M.write c' 0 (V.head c / V.head b)
forM_ [1..V.length c1] $ \x -> do
let ai = a V.! x
bi = b V.! x
ci = c V.! x
ci1' <- M.read c' (x1)
M.write c' x $ ci / (biai*ci1')
cf <- V.unsafeFreeze c'
d' <- V.thaw d
M.write d' 0 (V.head d / V.head b)
forM_ [1..V.length d1] $ \x -> do
let ai = a V.! x
bi = b V.! x
di = d V.! x
ci1 = cf V.! (x1)
di1' <- M.read d' (x1)
M.write d' x $ (diai*di1') / (biai*ci1)
df <- V.unsafeFreeze d'
xn <- M.new $ V.length d
M.write xn (V.length d1) $ V.last df
forM_ (reverse [0..V.length df2]) $ \ x-> do
let ci = cf V.! x
di = df V.! x
xi1 <- M.read xn $ x+1
M.write xn x $ di ci*xi1
V.unsafeFreeze xn