Opale
  presentation
  news
  faq
  docs
  team
  download
  Modules
 
2d
 
3d
 
ode
  matrix
 
parser
Applications
Bugs
 

Introduction / Functionalities

The 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 :

  • Support matrix with different storage technics : full, symetric, morse, band, etc ...
  • Linear systems inversion : direct methods (LU, Cholesky, etc), opmitized for each storage type ; efficient iterative methods, conjugate gradient, etc, for big linear systems.
  • Eigen values computing (no available method for now) : power method, etc ...

The use of Matrix module within Opale library is double :

  • as an autonomous module which can be used at will externally in other programs in which matrix computing is required;
  • but also as a basic tool module to develop more business oriented Opale modules, like the differential equation solving module (ODE) or the statistics module.

Examples

Here 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.






valid xhtml image