MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mathsFunc Namespace Reference

Namespace for some extra maths function that are often needed. More...

Functions

Mdouble gamma (Mdouble gamma_in)
 This is the gamma function returns the true value for the half integer value. More...
 
Mdouble chi_squared (Mdouble x, int k)
 This is a chi_squared function return the value x and degrees of freedom k. More...
 
Mdouble chi_squared_prob (Mdouble x, int k)
 This is the function which actually gives the probability back using a chi squared test. More...
 
template<typename T >
int sign (T val)
 This is a sign function, it returns -1 for negative numbers, 1 for positive numbers and 0 for 0. More...
 

Detailed Description

Namespace for some extra maths function that are often needed.

Function Documentation

Mdouble mathsFunc::chi_squared ( Mdouble  x,
int  k 
)

This is a chi_squared function return the value x and degrees of freedom k.

Definition at line 60 of file ExtendedMath.cc.

References gamma().

Referenced by chi_squared_prob().

61 {
62 
63 Mdouble prefactor = pow(2,k/2.0)*gamma(k/2.0);
64 Mdouble mainfactor = pow(x,k/2.0-1)*exp(x/-2.0);
65 
66 return mainfactor/prefactor;
67 
68 
69 
70 }
double Mdouble
Definition: ExtendedMath.h:33
Mdouble gamma(Mdouble gamma_in)
This is the gamma function returns the true value for the half integer value.
Definition: ExtendedMath.cc:37
Mdouble mathsFunc::chi_squared_prob ( Mdouble  x_max,
int  k 
)

This is the function which actually gives the probability back using a chi squared test.

This calulates the probabity based on a chi squared test First we calculated the cummelative chi_squared function.

This is the function which actually gives the probability back It is calculated by calling the normal chi_squated function and using the trapezoidal rule. The final results is 1-the cummulative chi_squared function

Definition at line 78 of file ExtendedMath.cc.

References chi_squared().

Referenced by RNG::test().

79 {
80 
81 //The current value was picked by tried were it stopped effect the 4 d.p.
82 const int num_steps_per_unit=100;
83 Mdouble sum=0;
84 Mdouble x=0;
85 long int num_steps=static_cast<int>(num_steps_per_unit*x_max);
86 //Use trapezional rule, but ignoring the ends
87 for (int i=0;i<num_steps;i++)
88  {
89  x=x_max/num_steps*(i+0.5);
90  sum=sum+chi_squared(x,k);
91  }
92 return 1.0-sum*x_max/num_steps;
93 
94 }
double Mdouble
Definition: ExtendedMath.h:33
Mdouble chi_squared(Mdouble x, int k)
This is a chi_squared function return the value x and degrees of freedom k.
Definition: ExtendedMath.cc:60
Mdouble mathsFunc::gamma ( Mdouble  gamma_in)

This is the gamma function returns the true value for the half integer value.

This is the gamma function, gives 'exact' answers for the half integer values This is done using the recussion relation and the known values for 1 and 0.5 Note, return NaN for non-half integer values.

Definition at line 37 of file ExtendedMath.cc.

References constants::sqrt_pi.

Referenced by chi_squared(), ChuteWithHopper::create_inflow_particle(), and ChuteWithHopperAndInset::create_inflow_particle().

38 {
39 const Mdouble ep=1e-5;
40 
41 if (gamma_in > 1.0+ep)
42  {
43  return ((gamma_in-1)*gamma(gamma_in-1));
44  }
45 else
46  {
47 
48  if ((gamma_in-ep<1.0) && (gamma_in+ep>1.0))
49  return 1.0;
50  else if ((gamma_in-ep<0.5) && (gamma_in+ep>0.5))
51  return constants::sqrt_pi;
52  else
53  return std::numeric_limits<Mdouble>::quiet_NaN();
54  }
55 }//end func gamma
const Mdouble sqrt_pi
Definition: ExtendedMath.h:55
double Mdouble
Definition: ExtendedMath.h:33
Mdouble gamma(Mdouble gamma_in)
This is the gamma function returns the true value for the half integer value.
Definition: ExtendedMath.cc:37
template<typename T >
int mathsFunc::sign ( val)

This is a sign function, it returns -1 for negative numbers, 1 for positive numbers and 0 for 0.

Definition at line 75 of file ExtendedMath.h.

Referenced by Screw::get_distance_and_normal().

76  {
77  return (T(0) < val) - (val < T(0));
78  }