require ‘matrix’

m = Matrix.identity(4)

v = Vector[5, 6, 7, 1]

puts m * v

gives the expected answer of [5, 6, 7, 1]

but

puts v * m

gives

ExceptionForMatrix::ErrDimensionMismatch: Matrix dimension mismatch

because the Vector#* method promotes self to a column vector when the

argument is found to be a Matrix. I think it should be promoting self

to a row vector and making this change removes the exception and gives

the correct result. The updated method is:

def *(x)

case x

when Numeric

els = @elements.collect{|e| e * x}

Vector.elements(els, false)

when Matrix

Matrix.row_vector(self) * x

else

s, x = x.coerce(self)

s * x

end

end

Dave.