Introduction / FunctionalitiesThe Opale library's Matrix module purpose is to provide a set of classes allowing building & managing usual matrices and also associated classic mathematical processes such as system solving or Eigen value computing, etc ... By design, the whole Matrix module classes must bring to developers or users a structured API, easily extensible, enough coherent to be almost intuitive. And so, basic classes support different types of matrix providing same services in same ways for every types. The solving of a linear system will be then simple since the building of the matrix until the choice of a solver and the call of the solving method. Matrix module functionalities :
The use of Matrix module within Opale library is double :
ExamplesHere is an example of matrix module use in an external program. We'll build a tri-diagonal matrix (use the matrix structure to store it in a "band" type) and inverse a linear system with a LU method. Here is the largely commented source code : import opale.mathtools.*; import opale.matrix.*; // matrix package import import opale.matrix.solver.*; // solver package import public class LUBand { public static void main(String[] arg) { int size = 100; //: size of the matrix to build // Declaration of the matrix size //, band width = 3 (tridiagonal matrix) BandMatrix A = new BandMatrix (size,3); for (int i=0; i < size; i++) // we fill the matrix { A.set(i,i,2); // the diagonal if (i > 0) { A.set(i,i-1,-7);} // the down diagonal if (i< size-1) { A.set(i,i+1,-7);} // the up diagonal } //System.out.println(A); //System.out.println(A.get(2,2)); DVect b = new DVect(size); // the second member DVect x = new DVect(size); // the solution vector b.set(0,1); // second member value (1;0;0;...;0) b.set(1,0); BandMatrix AA = (BandMatrix) A.clone(); // Optional : to keep the original matrix SolverLUBand lu = new SolverLUBand(); // we build a LU type solver optimized "band" storage lu.decomp(A); // we call the decomposition by LU of the matrix System.out.println("det = "+lu.determinant()); // display the determinant lu.solve(null,b,x); // we solve (no need to specify the matrix in the context // of a direct method, the matrix decomposition is used). System.out.println(x); // display the solution DVect err = new DVect(size); DVect Ax = new DVect(size); Ax = AA.mul(x); for (int i=0; i < size; i++) { err.set(i,Ax.get(i)-b.get(i)); } System.out.println("Err = "+err.getMax()); } } Opale Team : January 31 2004 23:14:10. |