Package xal.tools

Class ArrayMath

java.lang.Object
xal.tools.ArrayMath

public class ArrayMath extends Object
Provide some simple array math operations.
Author:
tap
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a new instance of ArrayMath
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[]
    elementProduct(double[] vec1, double[] vec2)
    Multiply two vectors element by element: m(i) = v1(i) * v2(i)
    static Object
    elementProduct(Object vec1, 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 Object
    elementSquareRoot(Object vector, int[] dimensions)
    Return the square root of each element: s(i1,i2,...) = squar_root( vec(i1,i2,...) )
    static Object
    elementSquareRootAbs(Object vector, int[] dimensions)
    Return the square root of each element: s(i1,i2,...) = squar_root( abs( vec(i1,i2,...) ) )
    static boolean
    invertMatrix(double[][] a)
    Invert the matrix in place - copied from reverseMatrix() in the the plot framework's GraphDataOperations
    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 Object
    multiply(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 Object
    subtract(Object vec1, 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 multiplying 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 Details

    • ArrayMath

      protected ArrayMath()
      Creates a new instance of ArrayMath
  • Method Details

    • 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 multiplying 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 Object subtract(Object vec1, 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 Object multiply(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 Object elementProduct(Object vec1, 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 Object elementSquareRoot(Object vector, int[] dimensions)
      Return the square root of each element: s(i1,i2,...) = squar_root( vec(i1,i2,...) )
    • elementSquareRootAbs

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

      public static boolean invertMatrix(double[][] a)
      Invert the matrix in place - copied from reverseMatrix() in the the plot framework's GraphDataOperations