gov.sns.tools
Class ArrayMath

java.lang.Object
  |
  +--gov.sns.tools.ArrayMath

public class ArrayMath
extends java.lang.Object

Provide some simple array math operations.


Constructor Summary
protected ArrayMath()
          Creates a new instance of ArrayMath
 
Method Summary
static double[] elementProduct(double[] vec1, double[] vec2)
          Multiply two vectors element by element: m(i) = v1(i) * v2(i)
static java.lang.Object elementProduct(java.lang.Object vec1, java.lang.Object vec2, int[] dimensions)
          Return the square root of each element: m(i1,i2,...) = v1(i1,i2,...) * v2(i1,i2,...)
static double[] elementSquareRoot(double[] vector)
          Return the square root of each element: s(i) = squar_root( vec(i) )
static java.lang.Object elementSquareRoot(java.lang.Object vector, int[] dimensions)
          Return the square root of each element: s(i1,i2,...) = squar_root( vec(i1,i2,...) )
static java.lang.Object elementSquareRootAbs(java.lang.Object vector, int[] dimensions)
          Return the square root of each element: s(i1,i2,...) = squar_root( abs( vec(i1,i2,...) ) )
static double[][] matrixProduct(double[] columnVector, double[] rowVector)
          Multiply a column vector by a row vector where the product is a matrix defined by: M(i,j) = columnVector(i) * rowVector(j) Note: This is not a scalar product, nor a vector product, but rather it is a product of a column vector with a row vector which results in a matrix.
static double[] multiply(double[][] matrix, double[] vector)
          Multiply a vector by a matrix defined by: v(i) = Sumj( mat(i,j) * vec(j) )
static double[] multiply(double[] vector, double scalar)
          Multiply a vector by a scalar: v(i) = vector(i) * scalar
static java.lang.Object multiply(java.lang.Object vector, double scalar, int[] dimensions)
          Return the square root of each element: m(i1,i2,...) = v(i1,i2,...) * scalar
static double scalarProduct(double[] vec1, double[] vec2)
          Calculate the scalar product of two vectors.
static double[][] subtract(double[][] mat1, double[][] mat2)
          Subtract two matrices M(i,j) = m1(i,j) - m2(i,j)
static double[] subtract(double[] vec1, double[] vec2)
          Subtract two vectors v(i) = v1(i) - v2(i)
static java.lang.Object subtract(java.lang.Object vec1, java.lang.Object vec2, int[] dimensions)
          Return the square root of each element: s(i1,i2,...) = v1(i1,i2,...) - v2(i1,i2,...)
static double[] transform(double[] array, double scale, double offset)
          Transform an array by mutlitplying by a scale and adding an offset v(i) = scale * array(i) + offset
static double[] translate(double[] array, double offset)
          Add a scalar to each element of an array v(i) = array(i) + offset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayMath

protected ArrayMath()
Creates a new instance of ArrayMath

Method Detail

translate

public static double[] translate(double[] array,
                                 double offset)
Add a scalar to each element of an array v(i) = array(i) + offset


transform

public static double[] transform(double[] array,
                                 double scale,
                                 double offset)
Transform an array by mutlitplying by a scale and adding an offset v(i) = scale * array(i) + offset


subtract

public static double[] subtract(double[] vec1,
                                double[] vec2)
Subtract two vectors v(i) = v1(i) - v2(i)


subtract

public static double[][] subtract(double[][] mat1,
                                  double[][] mat2)
Subtract two matrices M(i,j) = m1(i,j) - m2(i,j)


subtract

public static java.lang.Object subtract(java.lang.Object vec1,
                                        java.lang.Object vec2,
                                        int[] dimensions)
Return the square root of each element: s(i1,i2,...) = v1(i1,i2,...) - v2(i1,i2,...)


multiply

public static double[] multiply(double[] vector,
                                double scalar)
Multiply a vector by a scalar: v(i) = vector(i) * scalar


multiply

public static java.lang.Object multiply(java.lang.Object vector,
                                        double scalar,
                                        int[] dimensions)
Return the square root of each element: m(i1,i2,...) = v(i1,i2,...) * scalar


multiply

public static double[] multiply(double[][] matrix,
                                double[] vector)
Multiply a vector by a matrix defined by: v(i) = Sumj( mat(i,j) * vec(j) )


scalarProduct

public static double scalarProduct(double[] vec1,
                                   double[] vec2)
Calculate the scalar product of two vectors.


matrixProduct

public static double[][] matrixProduct(double[] columnVector,
                                       double[] rowVector)
Multiply a column vector by a row vector where the product is a matrix defined by: M(i,j) = columnVector(i) * rowVector(j) Note: This is not a scalar product, nor a vector product, but rather it is a product of a column vector with a row vector which results in a matrix.


elementProduct

public static java.lang.Object elementProduct(java.lang.Object vec1,
                                              java.lang.Object vec2,
                                              int[] dimensions)
Return the square root of each element: m(i1,i2,...) = v1(i1,i2,...) * v2(i1,i2,...)


elementProduct

public static double[] elementProduct(double[] vec1,
                                      double[] vec2)
Multiply two vectors element by element: m(i) = v1(i) * v2(i)


elementSquareRoot

public static double[] elementSquareRoot(double[] vector)
Return the square root of each element: s(i) = squar_root( vec(i) )


elementSquareRoot

public static java.lang.Object elementSquareRoot(java.lang.Object vector,
                                                 int[] dimensions)
Return the square root of each element: s(i1,i2,...) = squar_root( vec(i1,i2,...) )


elementSquareRootAbs

public static java.lang.Object elementSquareRootAbs(java.lang.Object vector,
                                                    int[] dimensions)
Return the square root of each element: s(i1,i2,...) = squar_root( abs( vec(i1,i2,...) ) )