0hc.net Menu
Home Overview
About Menu
Impressum

Orthonormality - Gram–Schmidt process

module Main where main :: IO () main = print $ ons [[2,2,0],[1,0,2],[0,2,1]] ons :: Floating a => [[a]] -> [[a]] ons vs = ons' vs [] ons' :: Floating a => [[a]] -> [[a]] -> [[a]] ons' [] ys = ys ons' (x:xs) ys = ons' xs $ ys ++ [map (\b -> b/zz) z] where z = vecSub x $ foldl vecAdd ll $ map (ons'' x) ys zz = vecNorm z ll = replicate (length x) 0 ons'' :: Num a => [a] -> [a] -> [a] ons'' x a = map (z*) a where z = vecSP x a vecSP :: Num a => [a] -> [a] -> a vecSP xs ys = sum $ zipWith (*) xs ys vecNorm :: Floating a => [a] -> a vecNorm xs = sqrt $ sum $ map (^2) xs vecSub :: Num a => [a] -> [a] -> [a] vecSub xs ys = zipWith (-) xs ys vecAdd :: Num a => [a] -> [a] -> [a] vecAdd xs ys = zipWith (+) xs ys
0hc.net    © 2001-2014 Harald Wolfsgruber