View Javadoc

1   package Jama.util;
2   
3   import Jama.Matrix;
4   
5   public class Maths {
6   
7      /** sqrt(a^2 + b^2) without under/overflow. **/
8   
9      public static double hypot(double a, double b) {
10        double r;
11        if (Math.abs(a) > Math.abs(b)) {
12           r = b/a;
13           r = Math.abs(a)*Math.sqrt(1+r*r);
14        } else if (b != 0) {
15           r = a/b;
16           r = Math.abs(b)*Math.sqrt(1+r*r);
17        } else {
18           r = 0.0;
19        }
20        return r;
21     }
22     
23     public static Matrix toJamaMatrix(hep.physics.matrix.Matrix mIn)
24     {
25        int nRows = mIn.getNRows();
26        int nCols = mIn.getNColumns();
27        Matrix result = new Matrix(nRows,nCols);
28        for (int i=0;i<nRows;i++)
29           for (int j=0; j<nCols;j++)
30              result.set(i,j,mIn.e(i,j));
31        return result;
32     }
33     public static hep.physics.matrix.Matrix fromJamaMatrix(Matrix mIn)
34     {
35        int nRows = mIn.getRowDimension();
36        int nCols = mIn.getColumnDimension();
37        hep.physics.matrix.BasicMatrix result = new hep.physics.matrix.BasicMatrix(nRows,nCols);
38        for (int i=0;i<nRows;i++)
39           for (int j=0; j<nCols; j++)
40              result.setElement(i,j,mIn.get(i,j));
41        return result;
42     }
43  }