Created
January 23, 2015 03:08
-
-
Save choupi/ccc55fb3b508e82c83d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mpla :: [[Float]] -> [Float] -> [Float] -> (Bool, [Float]) | |
mpla [] [] c = (False, c) | |
mpla (a:ax) (b:by) (c:cc) = (fl&&(s<0), rc) | |
where | |
s = b*(c+(mdot a cc)) | |
nc = case (s<0) of | |
True -> [c+(b*head a)] ++ (vadd a cc b) | |
False -> [c] ++ cc | |
(fl, rc) = mpla ax by nc | |
vadd :: [Float] -> [Float] -> Float -> [Float] | |
vadd [] [] _ = [] | |
vadd (a:ax) (b:bx) c = [a+b*c] ++ (vadd ax bx c) | |
mdot :: [Float] -> [Float] -> Float | |
mdot [] [] = 0 | |
mdot (a:ax) (b:bx) = a*b + (mdot ax bx) | |
main = print (mpla [[-1,1],[-2,-1],[3,3],[4,-4]] [1,1,-1,-1] [0,1,2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment