View Javadoc
1   import cern.colt.matrix.tfloat.FloatMatrix2D;
2   import cern.colt.matrix.tfloat.algo.SparseFloatAlgebra;
3   import cern.colt.matrix.tfloat.impl.SparseFloatMatrix2D;
4   
5   /**
6    * Demonstrate the COLT Matrix must be sparse problem.
7    * <p>
8    * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
9    * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
10   * <p>
11   * @version Aug 26, 2014 <br>
12   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
13   */
14  public class SparseMatrixProblem
15  {
16  
17      /**
18       * Execute the demo.
19       * @param args String[]; not used
20       */
21      public static void main(final String[] args)
22      {
23          float[][] values = { {1, 2, 3}, {3, 5, 7}, {5, 10, 0}};
24          Float determinant = null;
25  
26          FloatMatrix2D floatMatrix2D = new SparseFloatMatrix2D(values.length, values[0].length);
27          for (int row = 0; row < values.length; row++)
28          {
29              for (int column = 0; column < values[row].length; column++)
30              {
31                  floatMatrix2D.set(row, column, values[row][column]);
32              }
33          }
34          System.out.println("matrix: " + floatMatrix2D.toString());
35          System.out.println("calling SparseFloatAlgebra().det(this.matrixSI)");
36          try
37          {
38              determinant = new SparseFloatAlgebra().det(floatMatrix2D);
39          }
40          catch (IllegalArgumentException exception)
41          {
42              exception.printStackTrace();
43          }
44          System.out.println("determinant is " + determinant + " (should be 15.0)");
45      }
46  }