gov.nist.microanalysis.Utility
Class Math2

java.lang.Object
  extended by gov.nist.microanalysis.Utility.Math2

public class Math2
extends java.lang.Object

Useful math functions not provided in the standard libraries.

Copyright: Pursuant to title 17 Section 105 of the United States Code this software is not subject to copyright protection and is in the public domain

Company: National Institute of Standards and Technology

Version:
1.0
Author:
Nicholas W. M. Ritchie

Field Summary
static double[] MINUS_X_AXIS
           
static double[] MINUS_Y_AXIS
           
static double[] MINUS_Z_AXIS
           
static double[] ORIGIN_3D
           
static double SQRT_PI
          SQRT_PI - The square root of Pi ~ 1.772
static double[] X_AXIS
           
static double[] Y_AXIS
           
static double[] Z_AXIS
           
 
Constructor Summary
Math2()
           
 
Method Summary
static double angleBetween(double[] a, double[] b)
          angleBetween - Returns the angle between the vector a and vector b in radians.
static double[] cross(double[] a, double[] b)
          cross - Computes the cross product of two three-vectors a and b
static double distance(double[] p1, double[] p2)
          distance - What is the Euclidean distance between p1 and p2.
static double[] divide(double[] a, double b)
          divide - Returns a vector containing a, a vector, divided by b, a scalar.
static double dot(double[] a, double[] b)
          dot - Compute the dot product of two equal lengthed vectors
static double erf(double x)
          erf - The error function (2/sqrt(pi))*Integrate[Exp[-t^2],{t,0,x}]
Source: Numerical Recipes in C - 2nd Edition
static double erfc(double x)
          erfc - The complementary error function (1-erf(x))
Source: Numerical Recipes in C - 2nd Edition
static double expRand()
          expRand - Selects a random value from an exponential distibution.
static double gammaln(double xx)
          gammaln - The natural log of the gamma function.
static double gammap(double a, double x)
          gammap - Computes the incomplete gamma function P(a,x) by selecting between series and continued fraction representations based on the size of the arguments.
static double li(double x)
          li - A naive implementation of the Logarithmic Integral
static double magnitude(double[] p)
          magnitude - What is the length of the specified vector?
static double[] minus(double[] a, double[] b)
          minus - Returns the vector sum a + b
static double[] multiply(double a, double[] b)
          multiply - Returns a vector containing the product of a, a scalar, times b, a vector.
static double[] negative(double[] a)
          Returns a vector in which each of the coordinates equals -1 times the coordinates in a.
static double[] normalize(double[] p)
          normalize - Returns a copy of the input vector normalized to 1 length of 1.0.
static double[] plus(double[] a, double[] b)
          plus - Returns the vector sum a + b
static double sqr(double x)
          sqr - returns x*x
static double sum(double[] da)
          sum - Returns the sum of the specified array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORIGIN_3D

public static final double[] ORIGIN_3D

X_AXIS

public static final double[] X_AXIS

Y_AXIS

public static final double[] Y_AXIS

Z_AXIS

public static final double[] Z_AXIS

MINUS_X_AXIS

public static final double[] MINUS_X_AXIS

MINUS_Y_AXIS

public static final double[] MINUS_Y_AXIS

MINUS_Z_AXIS

public static final double[] MINUS_Z_AXIS

SQRT_PI

public static final double SQRT_PI
SQRT_PI - The square root of Pi ~ 1.772

Constructor Detail

Math2

public Math2()
Method Detail

sqr

public static final double sqr(double x)
sqr - returns x*x

Parameters:
x - double
Returns:
double

erf

public static final double erf(double x)
erf - The error function (2/sqrt(pi))*Integrate[Exp[-t^2],{t,0,x}]
Source: Numerical Recipes in C - 2nd Edition

Parameters:
x - double
Returns:
double

erfc

public static final double erfc(double x)
erfc - The complementary error function (1-erf(x))
Source: Numerical Recipes in C - 2nd Edition

Parameters:
x - double
Returns:
double

gammap

public static final double gammap(double a,
                                  double x)
gammap - Computes the incomplete gamma function P(a,x) by selecting between series and continued fraction representations based on the size of the arguments.
Source: Numerical Recipes in C - 2nd Edition

Parameters:
a - double
x - double
Returns:
double

gammaln

public static final double gammaln(double xx)
gammaln - The natural log of the gamma function.
Source: Numerical Recipes in C - 2nd Edition

Parameters:
xx - double
Returns:
double

expRand

public static final double expRand()
expRand - Selects a random value from an exponential distibution. The mean value returned is 1.0.

Returns:
double - Returns a random variable in the range [0,infinity)

distance

public static final double distance(double[] p1,
                                    double[] p2)
distance - What is the Euclidean distance between p1 and p2.

Parameters:
p1 -
p2 -
Returns:
double

magnitude

public static final double magnitude(double[] p)
magnitude - What is the length of the specified vector?

Parameters:
p -
Returns:
double

normalize

public static final double[] normalize(double[] p)
normalize - Returns a copy of the input vector normalized to 1 length of 1.0.

Parameters:
p - The vector to normalize
Returns:
A new vector containing the normalized result.

sum

public static final double sum(double[] da)
sum - Returns the sum of the specified array

Parameters:
da -
Returns:
The sum of the specified array

plus

public static final double[] plus(double[] a,
                                  double[] b)
plus - Returns the vector sum a + b

Parameters:
a -
b -
Returns:
The vector a+b

minus

public static final double[] minus(double[] a,
                                   double[] b)
minus - Returns the vector sum a + b

Parameters:
a -
b -
Returns:
The vector a+b

dot

public static final double dot(double[] a,
                               double[] b)
dot - Compute the dot product of two equal lengthed vectors

Parameters:
a -
b -
Returns:
The dot product of a and b

negative

public static final double[] negative(double[] a)
Returns a vector in which each of the coordinates equals -1 times the coordinates in a.

Parameters:
a -
Returns:
double [] = -a

cross

public static final double[] cross(double[] a,
                                   double[] b)
cross - Computes the cross product of two three-vectors a and b

Parameters:
a -
b -
Returns:
A three-vector perpendicular to both a and b and of length |a||b| sin(th) where th is the angle between a and b

multiply

public static final double[] multiply(double a,
                                      double[] b)
multiply - Returns a vector containing the product of a, a scalar, times b, a vector.

Parameters:
a -
b -
Returns:
A vector containing a*b

angleBetween

public static final double angleBetween(double[] a,
                                        double[] b)
angleBetween - Returns the angle between the vector a and vector b in radians.

Parameters:
a -
b -
Returns:
The angle 0.0 (parallel) to Pi (antiparallel)

divide

public static final double[] divide(double[] a,
                                    double b)
divide - Returns a vector containing a, a vector, divided by b, a scalar.

Parameters:
a -
b -
Returns:
A vector containing a/b

li

public static final double li(double x)
li - A naive implementation of the Logarithmic Integral

Parameters:
x -
Returns:
double