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

gutti philipp.guttenberg at gmx.net
Tue Dec 21 22:57:11 CET 2010

Hi Henning, Hi Alberto, 

thanks for the quick and comprehensive help. - I managed to implement
Hennings suggestion with mapVector and zipWithVector.  -- However have a
type inference problem with zipVectorWith -- probably a stupid beginners
mistake. (have a look below). I want to look into the matrix thing as well,
but that might take a bit.

Its very good to hear that HMatrix develpment is going on and there are
plans to implement more of Matlabs syntax. 

I see the point, that its probably not the "cleanest" way (bool to 0 & 1)
but its damn convinient (laziness at its best). 

Maybe there could be a haskell way to implement the "lazy" matlab matrix and
vector operation syntax (like explicit function for bool 2 num)

Cheers Phil   

######## Code

import Numeric.LinearAlgebra
import Graphics.Plot

time = 101 |> [0, 0.1 .. 100 :: Double];

vector1 = sin(time); 
vector2 = vector1*0.9;
posPart:: Vector Double -> Vector Double
posPart v  =  mapVector (\a -> if a>=0 then a else 0) v 

v3:: Vector Double -> Vector Double -> Vector Double
v3 v1 v2 = zipVectorWith(\a1 a2 -> if a1>=0 then a2/a1 else a1/a2) v1 v2

main = do  

  -- print(v3)
mplot [v3]
mplot [posPart vector1]

### Compile error
Couldn't match expected type `Vector Double'
           against inferred type `Vector Double
                                  -> Vector Double
                                  -> Vector Double'
    In the expression: v3
    In the first argument of `mplot', namely `[v3]'
    In a stmt of a 'do' expression: mplot [v3]

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-tp3312601p3314171.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

More information about the Haskell-Cafe mailing list