Add initial implementation for UE6 A5
This commit is contained in:
parent
b5eef0023e
commit
c6a82add73
@ -96,15 +96,36 @@ instance Eq MatrixF where
|
|||||||
-- Aufgabe A.5
|
-- Aufgabe A.5
|
||||||
|
|
||||||
instance Num MatrixF where
|
instance Num MatrixF where
|
||||||
(Mf t1 f1) + (Mf t2 f2) = error "Nicht implementiert!"
|
(Mf t1 f1) + (Mf t2 f2) = if t1 == t2 then Mf t1 (\x y -> (f1 x y) + (f2 x y)) else fehler
|
||||||
(Mf t1 f1) - (Mf t2 f2) = error "Nicht implementiert!"
|
(Mf t1 f1) - (Mf t2 f2) = if t1 == t2 then Mf t1 (\x y -> (f1 x y) - (f2 x y)) else fehler
|
||||||
(Mf t1 f1) * (Mf t2 f2) = error "Nicht implementiert!"
|
(Mf t1 f1) * (Mf t2 f2) = if snd t1 == fst t2 then Mf (fst t1, snd t2) (\x y -> (f1 x y) * (f2 x y)) else fehler
|
||||||
negate (Mf t f) = error "Nicht implementiert!"
|
negate (Mf t f) = if is_correct_matrix(Mf t f) then Mf t (\x y -> -(f x y)) else fehler
|
||||||
abs (Mf t f) = error "Nicht implementiert!"
|
abs (Mf t f) = if is_correct_matrix(Mf t f) then Mf t (\x y -> abs(f x y)) else fehler
|
||||||
signum (Mf t f) = error "Nicht implementiert!"
|
signum (Mf t f) = sign (Mf t f)
|
||||||
fromInteger n = error "Nicht implementiert!"
|
fromInteger n = Mf (1,1) (\x y -> fromIntegral(n))
|
||||||
|
|
||||||
|
sign :: MatrixF -> MatrixF
|
||||||
|
sign (Mf t f)
|
||||||
|
| not(is_correct_matrix(Mf t f)) = error "Vorzeichenfunktion undefiniert"
|
||||||
|
| True `elem` negative =
|
||||||
|
if False `elem` negative then error "Vorzeichenfunktion undefiniert"
|
||||||
|
else Mf (1,1) (\x y -> -1)
|
||||||
|
| True `elem` positive =
|
||||||
|
if False `elem` positive then error "Vorzeichenfunktion undefiniert"
|
||||||
|
else Mf (1,1) (\x y -> 1)
|
||||||
|
| True `elem` nulls =
|
||||||
|
if False `elem` nulls then error "Vorzeichenfunktion undefiniert"
|
||||||
|
else Mf (1,1) (\x y -> 0)
|
||||||
|
| otherwise = error "Vorzeichenfunktion undefiniert"
|
||||||
|
where
|
||||||
|
m = (Mf t f)
|
||||||
|
m' = construct_matrix m 1 []
|
||||||
|
negative = boolMatrixToList (map (map (<0)) m') []
|
||||||
|
nulls = boolMatrixToList (map (map (==0)) m') []
|
||||||
|
positive = boolMatrixToList (map (map (>0)) m') []
|
||||||
|
|
||||||
{- Knapp, aber gut nachvollziehbar geht die Instanzbildung fuer Num folgendermassen vor:
|
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