ejml library use mult() to multiply a matrix by a scalar

1.4k Views Asked by At

For example, I want to multiply the scalar, Gamma, by the NxN matrix, A, and return the result as the NxN matrix, B, i.e. B = Gamma * A.

First, I create DenseMatrix64F A, DenseMatrix64F B and double Gamma. Then, I would like to use the method:

org.ejml.ops.CommonOps.mult(Gamma, A, B);

I get a compiler error that Gamma is double that cannot be applied to mult() in CommonOps. The webpage for the mult method is here.

I don't know where I am going wrong. Please could you help me solve the problem?

1

There are 1 best solutions below

0
On

To perform element-by-element scalar multiplication, use org.ejml.CommonOps.scale.

In your case, try:

org.ejml.CommonOps.scale(double Gamma, DenseMatrix64F A, DenseMatrix64F B).

In your example, the error arises because the three-argument form of org.ejml.CommonOps.mult expects the first argument to be of type DenseMatrix64F, as in:

org.ejml.CommonOps.mult(DenseMatrix64F a, DenseMatrix64F b, DenseMatrix64F c)

As such, when you pass in a double as the first argument you will get a compiler error. Moreover, mult performs matrix multiplication c = a * b, which is not necessary for your example.