I want to solve the linear equation matrix*X=D using Colt library. I tried :
DoubleMatrix2D matrix;
matrix = new DenseDoubleMatrix2D(4,4);
for (int row = 0; row < 4; row++) {
for (int column = 0; column < 4; column++) {
// We set and get a cell value:
matrix.set(row,column,row+column);
}
}
DoubleMatrix2D D;
D = new DenseDoubleMatrix2D(4,1);
D.set(0,0, 1.0);
D.set(1,0, -1.0);
D.set(2,0, 91.0);
D.set(3,0, -5.0);
DoubleMatrix2D X;
X = solve(matrix,D);
but I get an error
"The method solve(DoubleMatrix2D, DoubleMatrix2D) is undefined for the type Test" ,
where Test is the name of the class.
What have I done wrong? Any ideas?...
The reason why you are getting this error is because method solve()
is non-static and can't be accessed from main()
.
This should solve your problem:
Algebra algebra = new Algebra();
DoubleMatrix2D X = algebra.solve(matrix, D);