[Haskell-cafe] Matlab Style Logic Operations ala V1.*(V2>0) on Vectors and Matrices with HMatrix ??

gutti philipp.guttenberg at gmx.net
Sun Dec 26 21:26:23 CET 2010


Jep, finally got it - that code works now. The Problem I had at the end was
that I didn't distinguish between type declaration of a function and a
value. -- the commented line for matrix 3 below shows what I did wrong. 

I think we can close that topic for now -  Thanks a lot for Your help
Henning, 

Cheers Phil 
 
#### Code ######

import Numeric.LinearAlgebra
import Graphics.Plot

matrix1:: Matrix Double 
matrix1 = fromLists [[1,2],[3,4],[5,6]]

matrix2:: Matrix Double
matrix2 = fromLists [[-1,2],[-3,4],[5,-6]]

funct:: Double -> Double -> Double
funct = \a1 a2 -> if a2>=0 then a1 else 0

matrixfunction:: (Double -> Double -> Double) -> Matrix Double -> Matrix
Double -> Matrix Double
matrixfunction f x y = liftMatrix2 (zipVectorWith f ) x y 

matrix3:: Matrix Double 
-- matrix3 :: (Double -> Double -> Double) -> Matrix Double -> Matrix Double
-> Matrix Double
matrix3 = matrixfunction funct matrix1 matrix2
disp = putStr . disps 2
          
main = do 

  disp matrix1
  disp matrix3

-- 
View this message in context: http://haskell.1045720.n5.nabble.com/Matlab-Style-Logic-Operations-ala-V1-V2-0-on-Vectors-and-Matrices-with-HMatrix-tp3312601p3318891.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list