Class MathFunction
java.lang.Object
llnl.gnem.core.util.MathFunctions.MathFunction
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
binomial
(int n, int k) Binomial(n,k) == n! / k! * (n - k )! //todo verify the conditionalsstatic 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.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 integerstatic 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 > 0static boolean
isBetween
(double value, double min, double max) Routine to reproduce the results of the SAC codes linrng_v function (linrng.c)static double
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
-
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
the factorial of an integer- Throws:
Exception
-
binomial
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 valuemin
- - the minimum valuemax
- - 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
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 vectorvectorB
- : the second N-dimensional vector- Returns:
- cos(theta)
-
dotprod
-
L2norm
Calculate the L2 norm: Sqrt(Sum of the Squares of an N-dimensional vector)- Parameters:
ndimensionalvector
-- Returns:
-