MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExtendedMath.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef EXTENDEDMATH_H
27 #define EXTENDEDMATH_H
28 
29 #include <iostream> //std::istream and std::stringstream
30 #include <fstream> //std::fstream
31 #include <cmath>
32 #include <limits>
33 
34 #include "Vector.h"
35 
36 /*
37  * \brief
38  */
39 namespace constants
40 {
41  //Values from WolframAlpha
42  const Mdouble pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068;
43  const Mdouble sqrt_pi = 1.772453850905516027298167483341145182797549456122387128213807789852911284591032181374950656738544665;
44  const Mdouble sqr_pi = 9.869604401089358618834490999876151135313699407240790626413349376220044822419205243001773403718552232;
45  const Mdouble sqrt_2 = 1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573;
46  const Mdouble sqrt_3 = 1.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248576;
47 }
48 
52 namespace mathsFunc
53 {
57  Mdouble gamma(Mdouble gamma_in);
58 
62  Mdouble chi_squared(const Mdouble x, const unsigned int k);
63 
67  Mdouble chi_squared_prob(const Mdouble x, const unsigned int k);
68 
78  double goldenSectionSearch(double (*function)(const double), double min, double cur, double max, double endCondition, double curVal = std::numeric_limits<Mdouble>::quiet_NaN());
79 
83  template<typename T> int sign(T val)
84  {
85  return (T(0) < val) - (val < T(0));
86  }
87 
91  template<typename T> T square(T val)
92  {
93  return val * val;
94  }
95 
99  template<typename T> T cubic(T val)
100  {
101  return val * val * val;
102  }
103 
111  bool isEqual(Mdouble v1,Mdouble v2, double absError);
119  bool isEqual(Vec3D v1, Vec3D v2, double absError);
120 
124  template<typename T> constexpr T factorial(const T t)
125  {
126  return (t == 0) ? 1 : t * factorial(t - 1);
127  }
128 
129 }
130 
134 namespace besselFunc
135 {
136 
137  Mdouble chebyshev(Mdouble x, const Mdouble coef[], int N);
138 
140 
141  Mdouble I0(Mdouble x);
142 
143 }
144 
145 #endif
Mdouble chebyshev(Mdouble x, const Mdouble coef[], int N)
Mdouble chi_squared_prob(const Mdouble x, const unsigned int k)
This is the function which actually gives the probability back using a chi squared test...
Definition: ExtendedMath.cc:86
Mdouble I0_exp(Mdouble x)
const Mdouble sqrt_pi
Definition: ExtendedMath.h:43
double Mdouble
int sign(T val)
This is a sign function, it returns -1 for negative numbers, 1 for positive numbers and 0 for 0...
Definition: ExtendedMath.h:83
T square(T val)
squares a number
Definition: ExtendedMath.h:91
constexpr T factorial(const T t)
factorial function
Definition: ExtendedMath.h:124
const Mdouble pi
Definition: ExtendedMath.h:42
T cubic(T val)
calculates the cube of a number
Definition: ExtendedMath.h:99
const Mdouble sqrt_2
Definition: ExtendedMath.h:45
bool isEqual(Mdouble v1, Mdouble v2, double absError)
Compares the difference of two Mdouble with an absolute error, useful in UnitTests.
double goldenSectionSearch(double(*function)(const double), double min, double cur, double max, double endCondition, double curVal=std::numeric_limits< Mdouble >::quiet_NaN())
This function performs a golden section search to find the location of the minimum of a function...
Mdouble gamma(Mdouble gamma_in)
This is the gamma function returns the true value for the half integer value.
Definition: ExtendedMath.cc:47
Mdouble chi_squared(const Mdouble x, const unsigned int k)
This is a chi_squared function return the value x and degrees of freedom k.
Definition: ExtendedMath.cc:70
Mdouble I0(Mdouble x)
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
const Mdouble sqrt_3
Definition: ExtendedMath.h:46
const Mdouble sqr_pi
Definition: ExtendedMath.h:44