f1 :: Mesh -> Matrix Double
f1 me = knx where
hx :: Double
(hx , _) = h me
a, knx :: Matrix Double
a = fromLists [[1,2], [3,4]]
knx = hx * a
-- knx = 2 * a
I don't get why in the above function, mutliplying by 2 works whereas multiplying by hx = 0.5 doesn't. OTOH, multiplying a Matrix Double
with a Double
outside a function works as it should.
Couldn't match expected type ‘Matrix Double’
with actual type ‘Double’
In the first argument of ‘(*)’, namely ‘hx’
In the expression: hx * a
Failed, modules loaded: none.
I am seriously puzzled. Any pointers are welcome!
In HMatrix
, scale :: Container c e => e -> c e -> c e
does what it says on the label (multiplies the e
in a c e
by the first e
). Here are some usage examples here: https://hackage.haskell.org/package/hmatrix-0.16.1.4/docs/src/Data-Packed-Internal-Numeric.html
It should be noted that scale x
constructs a Container type by considering x a singleton list, via fromList
.
It would be really handy if at least the common arithmetic operations would be overloaded, so that formulas may resemble their mathematical counterpart. I'm not sure whether defining function synonyms (e.g. (.*) = scale
) would be a good idea or it would just add a layer of complexity. Any thoughts?