1

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?

Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74
dulang10
  • 11
  • 2
  • Welcome to Stack Overflow. This is not a good way to ask a question here. Did you try anything so far to solve your problem? Show your effort first so people might show theirs. Please read [FAQ](http://stackoverflow.com/tour), [How to Ask](http://stackoverflow.com/help/how-to-ask) and [help center](http://stackoverflow.com/help) as a start. – Nahuel Ianni Sep 11 '14 at 16:54

1 Answers1

0

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.

DontDivideByZero
  • 1,171
  • 15
  • 28