Question

It seems that I can`t use this Apache Commons Math library in my class because I get unexpected token on matrixSim when I try to use RealMatrix in my consructor like this:

class vecGenUn
{
  double[][] prevMat;
  RealMatrix matrixSim;  //this is problematic
  int dataDim;
  int rowDim;
  double simVecMean;
  double simVecSD;
  double simVecUn;
  double sum;

  vecGenUn (double[][] tempPM)
  {
    prevMat = tempSM;
    matrixSim = new Array2DRowRealMatrix(prevMat);  //and possibly this
    dataDim = new int matrixSim.getColumnDimension();
    rowDim = new int matrixSim.getRowDimension();
    simVecMean = new double[dataDim];
    simVecSD = new double[dataDim];
    simVecUn = new double[dataDim];
    sum = new Sum();
  }

  public void vecGen()
  {
    for (int i = 0; i < dataDim; i++)
    {
      simVecMean[i] = sum.evaluate(matrixSim.getColumn(i), 0, rowDim)/rowDim
    }
  }
}

Now methods are yet to be implemented but how do I use RealMatrix data type here when I need it for all Appache math library methods but also I need to construct it from values (double array) supplied when creating this class instance.

Was it helpful?

Solution

In the code provided, you have all sorts of compiler errors unrelated to Apache Commons Math. Fix those before trying to determine if you have problems with that library.

Correction comments are in-line marked with (*):

class vecGenUn
{
  double[][] prevMat;
  RealMatrix matrixSim;  //this is problematic
  int dataDim;
  int rowDim;
  double simVecMean;
  double simVecSD;
  double simVecUn;
  double sum;

  vecGenUn (double[][] tempPM)
  {
    prevMat = tempSM; // (*) tempSM is undefined
    matrixSim = new Array2DRowRealMatrix(prevMat);  //and possibly this
    dataDim = new int matrixSim.getColumnDimension(); // (*) 'new int' is invalid
    rowDim = new int matrixSim.getRowDimension(); // (*) ditto
    simVecMean = new double[dataDim]; // (*) assigning an array to a scalar variable
    simVecSD = new double[dataDim]; // (*) ditto
    simVecUn = new double[dataDim]; // (*) ditto
    sum = new Sum(); // (*) assigning object to primitive
  }

  public void vecGen()
  {
    for (int i = 0; i < dataDim; i++)
    {
      simVecMean[i] = sum.evaluate(matrixSim.getColumn(i), 0, rowDim)/rowDim // (*) indexing a scalar variable
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top