| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
grad_2F1.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_GRAD_2F1_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_GRAD_2F1_HPP
3
4 #include <cmath>
5
6 namespace stan {
7
8 namespace math {
9
10 // Gradient of the hypergeometric function 2F1(a, b | c | z)
11 // with respect to a and c
12 template<typename T>
13 void grad_2F1(T& gradA, T& gradC, T a, T b, T c, T z, T precision = 1e-6) {
14 using std::fabs;
15
16 gradA = 0;
17 gradC = 0;
18
19 T gradAold = 0;
20 T gradCold = 0;
21
22 int k = 0;
23 T tDak = 1.0 / (a - 1);
24
25 while (fabs(tDak * (a + (k - 1)) ) > precision || k == 0) {
26 const T r = ( (a + k) / (c + k) ) * ( (b + k) / (T)(k + 1) ) * z;
27 tDak = r * tDak * (a + (k - 1)) / (a + k);
28
29 if (r == 0) break;
30
31 gradAold = r * gradAold + tDak;
32 gradCold = r * gradCold - tDak * ((a + k) / (c + k));
33
34 gradA += gradAold;
35 gradC += gradCold;
36
37 ++k;
38
39 if (k > 200) break;
40 }
41 }
42
43
44 }
45
46 }
47
48 #endif
stan::math::fabs
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:14
stan::math::e
double e()
Return the base of the natural logarithm.
Definition: constants.hpp:95
stan::math::grad_2F1
void grad_2F1(T &gradA, T &gradC, T a, T b, T c, T z, T precision=1e-6)
Definition: grad_2F1.hpp:13

[ Stan Home Page ] © 2011–2015, Stan Development Team.