Add sign function to UE3 A.4
This commit is contained in:
parent
57b468af75
commit
2123b282bc
@ -83,6 +83,8 @@ Solution:
|
||||
|
||||
Aufgabe A.4
|
||||
|
||||
Implement each of the num functions for the matrices
|
||||
|
||||
> instance Num Matrix where
|
||||
> (+) m1 m2 = (add m1 m2)
|
||||
> (-) m1 m2 = (diff m1 m2)
|
||||
@ -122,14 +124,23 @@ Aufgabe A.4
|
||||
> sign :: Matrix -> Matrix
|
||||
> sign (M m1)
|
||||
> | matrixtyp (M m1) == KeineMatrix = error "Vorzeichenfunktion undefiniert"
|
||||
> | [True] `elem` negative && [False] `elem` negative = error "Vorzeichenfunktion undefiniert"
|
||||
> | [True] `elem` positive && [False] `elem` positive = error "Vorzeichenfunktion undefiniert"
|
||||
> | [True] `elem` nulls && [False] `elem` nulls = error "Vorzeichenfunktion undefiniert"
|
||||
> | [True] `elem` nulls = M([[0]])
|
||||
> | [True] `elem` positive = M([[1]])
|
||||
> | [True] `elem` negative = M([[-1]])
|
||||
> | True `elem` negative =
|
||||
> if False `elem` negative then error "Vorzeichenfunktion undefiniert"
|
||||
> else M([[-1]])
|
||||
> | True `elem` positive =
|
||||
> if False `elem` positive then error "Vorzeichenfunktion undefiniert"
|
||||
> else M([[1]])
|
||||
> | True `elem` nulls =
|
||||
> if False `elem` nulls then error "Vorzeichenfunktion undefiniert"
|
||||
> else M([[0]])
|
||||
> | otherwise = error "Vorzeichenfunktion undefiniert"
|
||||
> where
|
||||
> negative = map (map (<0)) m1
|
||||
> nulls = map (map (==0)) m1
|
||||
> positive = map (map (>0)) m1
|
||||
> negative = boolMatrixToList (map (map (<0)) m1) []
|
||||
> nulls = boolMatrixToList (map (map (==0)) m1) []
|
||||
> positive = boolMatrixToList (map (map (>0)) m1) []
|
||||
|
||||
> boolMatrixToList :: [[Bool]] -> [Bool] -> [Bool]
|
||||
> boolMatrixToList (m:ms) res
|
||||
> | null m = res
|
||||
> | length m /= 0 && null ms = res ++ m
|
||||
> | otherwise = boolMatrixToList ms (res ++ m)
|
||||
|
Reference in New Issue
Block a user