Closed fedeinthemix closed 8 years ago
You did nothing wrong. (*)
is element-by-element multiplication of two vectors or two matrices. Both arguments in the standard (*)
operator must be of the same type. For convenience, the instance of (*)
in hmatrix automatically expands arrays of one single element:
λ> let v = vector [1,2,3]
λ> let w = vector [5,10,15]
λ> v * w
fromList [5.0,20.0,45.0]
λ> vector [3] * v
fromList [3.0,6.0,9.0]
λ> 3 * v
fromList [3.0,6.0,9.0]
In the last case the polymorphic literal 3
is interpreted as vector [3]
The problem is that iC
is just a complex number, not a polymorphic numeric literal, and then it cannot be combined with a vector. We can use scale
or scalar
:
λ> scalar 3 :: Vector R
fromList [3.0]
λ> scalar 3 * v
fromList [3.0,6.0,9.0]
λ> scale iC (fromList [1,2,3])
fromList [0.0 :+ 1.0,0.0 :+ 2.0,0.0 :+ 3.0]
λ> scalar iC * fromList [1,2,3]
fromList [0.0 :+ 1.0,0.0 :+ 2.0,0.0 :+ 3.0]
Makes a lot of sense. Thanks for the explanation!
One can scale a vector, where the scale factor is a complex number, with scale. However, the (*) operator appears not to work with a complex scalar:
With real vectors and scalar factors both scale, and (*) work as I would expect:
Is this intended? Am I doing something wrong?