I have quite a naive question, concerning the the Matrix Toolkit Java (MTJ): how to I build a Matrix B starting from a double[][] A?
Cause, within the library, Matrix is only an interface and not a class.
EDIT
So, I thought that having JAMA and 'MTJ' would have solved the problem, since in JAMA it's possible to directly define Matrix objects, but it hasn't worked.
My code is this:
import java.util.Arrays; import Jama.; import no.uib.cipr.matrix.;
public class MainCalc extends TurbulentModel {
public static void main(String[] args){
// TurbulentModel A = new TurbulentModel();
// A.numberOfPointsAlongX = 4096;
// A.numberOfPointsAlongY = 3;
// A.numberOfPointsAlongZ = 3;
// A.averageHubWindSpeed = 8;
// A.durationOfWindFile = 600;
// A.hubHeight = 90;
// A.turbulentSeedNumber = 1;
// A.volumeWidthAlongY = 150;
// A.volumeHeightAlongZ = 150;
// float[] pointsYCoord = A.calcPointsYCoord();
// float[] pointsZCoord = A.calcPointsZCoord();
double[][] rr = {{2, -1, 0},{-1, 2, -1},{0, -1, 2}};
Matrix test = new Matrix(rr);
LowerTriangPackMatrix test1 = new LowerTriangPackMatrix(test);
System.exit(0);
}
}
But it is resolved into an evident conflict between JAMAsMatrixconcept and MTJ'sMatrix` definition.
How shall I solve the issue?
You don't need JAMA to create a matrix in MTJ. In fact, as you've already found, JAMA is going to get in the way of MTJ.
The simplest approach to creating a matrix object in MTJ is to use the
DenseMatrixclass which implements theMatrixinterface. One of its constructors accepts adouble[][]and creates a matrix whose entries are those given in the input array. For example,There are other constructors available, but these two forms seem the most pertinent to your needs. You should consult the javadoc (be aware that this isn't for the latest version 1.01, but seems close) for more options.
I assume that you need dense storage for you matrix. If you have a sparse matrix, then there are other classes in MTJ which you should use in place of
DenseMatrixsuch as theCompColMatrixorSymmTridiagMatrixclasses. Which of these sparse matrix classes you would use depends on the type of sparseness inherent to the matrix being represented.When in doubt, however, the dense storage approach will work for all possible matricies. The benefit to using sparse matricies is speed and storage space, but only for matricies which are appropriately sparse.