Class MathFunction

java.lang.Object
llnl.gnem.core.util.MathFunctions.MathFunction

public class MathFunction extends Object
This class is for general math functions not available in java.Math User: matzel Date: Aug 2, 2006 Time: 4:05:28 PM
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    binomial(int n, int k)
    Binomial(n,k) == n! / k! * (n - k )! //todo verify the conditionals
    static int
    closestPowerOf2(int num)
    Find the closest power of 2 to the input number e.g.
    static long
    closestPowerOf2(long num)
    Find the closest power of 2 to the input number e.g.
    dotprod(List<Double> vectorA, List<Double> vectorB)
     
    static double
    erf(double z)
    Generalized power series for the error function erf(z) erf(z) = 2/sqrt(PI) * SUM(k = 0:inf) [ -1^k * z^(2k+1) / (k!*(2k+1)) ]
    static double
    factorial(double z)
     
    static double
    factorial(int n)
    the factorial of an integer
    static double
    Gamma(double z)
    The Euler Gamma function (ref: functions.wolfram.com) Gamma(z) = Integral(0-inf) [ t^(z-1) * e^(-t) * dt ] below is an approximate expansion (to order 10) |Arg(z)| < pi /\ (|z| --> inf.)
    getCosineTheta(List<Double> vectorA, List<Double> vectorB)
    Given 2 vectors, A and B, get the cosine of the angle between the two.
    static double
    Heaviside(double value)
    The Heavyside step function H(x) = 0.0 when x < 0 = 0.5 when x == 0 = 1.0 when x > 0
    static boolean
    isBetween(double value, double min, double max)
    Routine to reproduce the results of the SAC codes linrng_v function (linrng.c)
    static double
    L2norm(List<Double> ndimensionalvector)
    Calculate the L2 norm: Sqrt(Sum of the Squares of an N-dimensional vector)
    static int
    nextPowerOf2(int num)
    Round up an integer to the next power of 2 e.g.
    static long
    nextPowerOf2(long num)
    Find the next power of 2 greater than the input number e.g.
    static double
    randomBetween(double low, double high)
    create a random value between two values

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MathFunction

      public MathFunction()
  • Method Details

    • Heaviside

      public static double Heaviside(double value)
      The Heavyside step function H(x) = 0.0 when x < 0 = 0.5 when x == 0 = 1.0 when x > 0
      Parameters:
      value - the original value
      Returns:
      Heavyside(value)
    • closestPowerOf2

      public static long closestPowerOf2(long num)
      Find the closest power of 2 to the input number e.g. 5 ==> 4, 100 ==> 128, 2==>2 etc.
      Parameters:
      num - a long valued variable
      Returns:
      the nearest power of 2 greater than num
    • nextPowerOf2

      public static long nextPowerOf2(long num)
      Find the next power of 2 greater than the input number e.g. 5 ==> 8, 100 ==> 128, 2==>2 etc.
      Parameters:
      num - a long valued variable
      Returns:
      the nearest power of 2 greater than num
    • nextPowerOf2

      public static int nextPowerOf2(int num)
      Round up an integer to the next power of 2 e.g. 5 ==> 8, 100 ==> 128, 2==>2 etc.
      Parameters:
      num - an integer
      Returns:
      the smallest power of 2 greater than num
    • closestPowerOf2

      public static int closestPowerOf2(int num)
      Find the closest power of 2 to the input number e.g. 5 ==> 4, 100 ==> 128, 2==>2 etc.
      Parameters:
      num - an integer
      Returns:
      the closest power of 2
    • Gamma

      public static double Gamma(double z)
      The Euler Gamma function (ref: functions.wolfram.com) Gamma(z) = Integral(0-inf) [ t^(z-1) * e^(-t) * dt ] below is an approximate expansion (to order 10) |Arg(z)| < pi /\ (|z| --> inf.)
    • factorial

      public static double factorial(double z)
    • factorial

      public static double factorial(int n) throws Exception
      the factorial of an integer
      Throws:
      Exception
    • binomial

      public static double binomial(int n, int k) throws Exception
      Binomial(n,k) == n! / k! * (n - k )! //todo verify the conditionals
      Throws:
      Exception
    • erf

      public static double erf(double z)
      Generalized power series for the error function erf(z) erf(z) = 2/sqrt(PI) * SUM(k = 0:inf) [ -1^k * z^(2k+1) / (k!*(2k+1)) ]
    • isBetween

      public static boolean isBetween(double value, double min, double max)
      Routine to reproduce the results of the SAC codes linrng_v function (linrng.c)
      Parameters:
      value - - the actual value
      min - - the minimum value
      max - - the maximum value
      Returns:
      - true if the value falls between the minimum and the maximum
    • randomBetween

      public static double randomBetween(double low, double high)
      create a random value between two values
      Parameters:
      low -
      high -
      Returns:
    • getCosineTheta

      public Double getCosineTheta(List<Double> vectorA, List<Double> vectorB)
      Given 2 vectors, A and B, get the cosine of the angle between the two. A.B = |A||B| cos(theta)
      Parameters:
      vectorA - : the first N-dimensional vector
      vectorB - : the second N-dimensional vector
      Returns:
      cos(theta)
    • dotprod

      public Double dotprod(List<Double> vectorA, List<Double> vectorB)
    • L2norm

      public static double L2norm(List<Double> ndimensionalvector)
      Calculate the L2 norm: Sqrt(Sum of the Squares of an N-dimensional vector)
      Parameters:
      ndimensionalvector -
      Returns: