ibspan.ecap.shared.util
Class MyMath

java.lang.Object
  extended by ibspan.ecap.shared.util.MyMath

public class MyMath
extends java.lang.Object

Compilation: javac MyMath.java Execution: java MyMath z Implements a number of mathematical functions: absolute value, square root, exponential, error function, and the cumulative Gaussian distribution. Also produces random Gaussians. The first three are for illustration only, since they are already in the standard Math library. The test client reads in a command line inputs z and prints out erf(z) and Phi(z) to 7 significant digits, where erf(z) = 2 / sqrt(pi) * integral(exp(-t*t), t = 0..z) Phi(z) = normal cdf % java MyMath 1.0 abs(1.0) = 1.0 exp(1.0) = 2.7182818284590455 cosh(1.0) = 1.543080634815244 sqrt(1.0) = 1.0 erf(1.0) = 0.8427007877600067 // actual = 0.84270079294971486934 Phi(1.0) = 0.8413447386043253 // actual = 0.8413447460 % java MyMath -1.0 abs(-1.0) = 1.0 exp(-1.0) = 0.36787944117144245 cosh(-1.0) = 1.543080634815244 sqrt(-1.0) = NaN erf(-1.0) = -0.8427007877600068 Phi(-1.0) = 0.15865526139567465 % java MyMath 3.0 abs(3.0) = 3.0 exp(3.0) = 20.08553692318766 cosh(3.0) = 10.067661995777765 sqrt(3.0) = 1.7320508075688772 erf(3.0) = 0.9999779095015785 // actual = 0.99997790950300141456 Phi(3.0) = 0.9986501019267444 % java MyMath 30 abs(30.0) = 30.0 exp(30.0) = 1.0686474581524467E13 cosh(30.0) = 5.343237290762231E12 sqrt(30.0) = 5.477225575051661 erf(30.0) = 1.0 Phi(30.0) = 1.0 % java MyMath -30 abs(-30.0) = 30.0 exp(-30.0) = 9.357622968840171E-14 cosh(-30.0) = 5.343237290762231E12 sqrt(-30.0) = NaN erf(-30.0) = -1.0 Phi(-30.0) = 0.0 % java MyMath 1E-20 abs(1.0E-20) = 1.0E-20 exp(1.0E-20) = 1.0 cosh(1.0E-20) = 1.0 sqrt(1.0E-20) = 9.999999999999999E-11 erf(1.0E-20) = -3.0000000483809686E-8 // true anser 1.13E-20 Phi(1.0E-20) = 0.49999998499999976 Reference: Chebyshev fitting formula for erf(z) from Numerical Recipes, 6.2


Constructor Summary
MyMath()
           
 
Method Summary
static double abs(double x)
           
static double cosh(double x)
          Hyperbolic trig functions
static double erf(double z)
           
static double erf2(double z)
           
static double exp(double x)
           
static double gaussian()
           
static double gaussian(double mu, double sigma)
           
static double phi(double x)
           
static double Phi(double z)
           
static double phi(double x, double mu, double sigma)
           
static double Phi(double z, double mu, double sigma)
           
static double Phi2(double z)
           
static int random(int N)
           
static double sinh(double x)
           
static double sqrt(double c)
           
static double tanh(double x)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MyMath

public MyMath()
Method Detail

abs

public static double abs(double x)

exp

public static double exp(double x)

sqrt

public static double sqrt(double c)

erf

public static double erf(double z)

erf2

public static double erf2(double z)

phi

public static double phi(double x)

phi

public static double phi(double x,
                         double mu,
                         double sigma)

Phi2

public static double Phi2(double z)

Phi

public static double Phi(double z)

Phi

public static double Phi(double z,
                         double mu,
                         double sigma)

random

public static int random(int N)

gaussian

public static double gaussian()

gaussian

public static double gaussian(double mu,
                              double sigma)

cosh

public static double cosh(double x)
Hyperbolic trig functions


sinh

public static double sinh(double x)

tanh

public static double tanh(double x)