2

How can I multiply RealVector by matrix (v*M) in apache-commons-math library? I found only multiply Matrix by Matrix and Matrix by RealVector.

Jerome
  • 35
  • 6
  • What result do you expect when you would multiply a vector with a matrix? Hint: it can't be done: http://mathinsight.org/matrix_vector_multiplication. If your matrix is one-dimension anyway, consider conversion to a vector. – Munchhausen Sep 20 '16 at 18:01
  • I need multiply [x,y,z,1] by 4*4 matrix for affine transformation, so I expect a new vector eg [x,y,0,w] – Jerome Sep 20 '16 at 18:10
  • @Munchhausen This is possible, if the vector is a row vector. – fabian Sep 20 '16 at 18:35

1 Answers1

1

preMultiply seems to be the method you're looking for.

RealVector vector = ...
RealMatrix matrix = ...
RealVector result = matrix.preMultiply(vector);
fabian
  • 80,457
  • 12
  • 86
  • 114