Miscellaneous math functions.
More...
Go to the source code of this file.
Miscellaneous math functions.
- Author
- A. Mignone (migno.nosp@m.ne@p.nosp@m.h.uni.nosp@m.to.i.nosp@m.t) B. Vaidya
- Date
- June 28, 2015
Definition in file math_misc.c.
double BesselI0 |
( |
double |
x | ) |
|
Returns the modified Bessel function I0(x) for any real x. (Adapted from Numerical Recipes)
Definition at line 80 of file math_misc.c.
89 if ((ax=fabs(x)) < 3.75) {
92 ans = 1.0 + y*(3.5156229+y*(3.0899424
93 + y*(1.2067492 + y*(0.2659732 + y*(0.360768e-1
97 ans = (exp(ax)/sqrt(ax))*(0.39894228 + y*(0.1328592e-1
98 + y*(0.225319e-2 + y*(-0.157565e-2 + y*(0.916281e-2
99 + y*(-0.2057706e-1 + y*(0.2635537e-1
100 + y*(-0.1647633e-1 + y*0.392377e-2))))))));
double BesselI1 |
( |
double |
x | ) |
|
Returns the modified Bessel function I1(x) for any real x. (Adapted from Numerical Recipes)
Definition at line 107 of file math_misc.c.
114 double ax, ans1, ans2, ans;
116 if ((ax=fabs(x)) < 3.75) {
119 ans = ax*(0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934
120 +y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3))))));
123 ans1 = 0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1
125 ans2 = 0.39894228+y*(-0.3988024e-1 + y*(-0.362018e-2
126 + y*(0.163801e-2+y*(-0.1031555e-1+y*ans1))));
127 ans = ans2*(exp(ax)/sqrt(ax));
129 return x < 0.0 ? -ans : ans;
double BesselJ0 |
( |
double |
x | ) |
|
Returns the Bessel function J0(x) for any real x. (Adapted from Numerical Recipes)
Definition at line 13 of file math_misc.c.
21 double xx,y,ans,ans1,ans2;
23 if ((ax=fabs(x)) < 8.0) {
25 ans1 = 57568490574.0+y*(-13362590354.0+y*(651619640.7
26 + y*(-11214424.18+y*(77392.33017+y*(-184.9052456)))));
27 ans2 = 57568490411.0+y*(1029532985.0+y*(9494680.718
28 + y*(59272.64853+y*(267.8532712+y*1.0))));
34 ans1 = 1.0 + y*(-0.1098628627e-2+y*(0.2734510407e-4
35 + y*(-0.2073370639e-5+y*0.2093887211e-6)));
36 ans2 = - 0.1562499995e-1+y*(0.1430488765e-3
37 + y*(-0.6911147651e-5+y*(0.7621095161e-6
38 - y*0.934945152e-7)));
39 ans = sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
double BesselJ1 |
( |
double |
x | ) |
|
Returns the Bessel function J1(x) for any real x. (Adapted from Numerical Recipes)
Definition at line 45 of file math_misc.c.
53 double xx,y,ans,ans1,ans2;
54 if ((ax=fabs(x)) < 8.0) {
57 ans1 = x*(72362614232.0+y*(-7895059235.0+y*(242396853.1
58 + y*(-2972611.439+y*(15704.48260+y*(-30.16036606))))));
59 ans2 = 144725228442.0+y*(2300535178.0+y*(18583304.74
60 + y*(99447.43394+y*(376.9991397+y*1.0))));
66 ans1 = 1.0 +y*(0.183105e-2+y*(-0.3516396496e-4
67 + y*(0.2457520174e-5+y*(-0.240337019e-6))));
68 ans2 = 0.04687499995+y*(-0.2002690873e-3
69 + y*(0.8449199096e-5+y*(-0.88228987e-6
70 + y*0.105787412e-6)));
71 ans = sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
72 if (x < 0.0) ans = -ans;
double BesselK0 |
( |
double |
x | ) |
|
Returns the modified Bessel function K0(x) for any real x. (Adapted from Numerical Recipes)
Definition at line 134 of file math_misc.c.
146 ans = (-log(x/2.0)*I0)+(-0.57721566+y*(0.42278420
147 + y*(0.23069756+y*(0.3488590e-1
148 + y*(0.262698e-2 +y*(0.10750e-3+y*0.74e-5))))));
151 ans = (exp(-x)/sqrt(x))*(1.25331414+y*(-0.7832358e-1
152 + y*(0.2189568e-1+y*(-0.1062446e-1+y*(0.587872e-2
153 + y*(-0.251540e-2+y*0.53208e-3))))));
double BesselI0(double x)
double BesselK1 |
( |
double |
x | ) |
|
Returns the modified Bessel function K1(x) for any real x. (Adapted from Numerical Recipes)
Definition at line 159 of file math_misc.c.
171 ans = (log(x/2.0)*I1)+(1.0/x)*(1.0+y*(0.15443144
172 + y*(-0.67278579+y*(-0.18156897+y*(-0.1919402e-1
173 + y*(-0.110404e-2+y*(-0.4686e-4)))))));
176 ans = (exp(-x)/sqrt(x))*(1.25331414+y*(0.23498619 +y*(-0.3655620e-1
177 + y*(0.1504268e-1+y*(-0.780353e-2
178 + y*(0.325614e-2+y*(-0.68245e-3)))))));
double BesselI1(double x)
double BesselKn |
( |
int |
n, |
|
|
double |
x |
|
) |
| |
Returns the modified Bessel function Kn(x) for positive x and n >= 2. (Adapted from Numerical Recipes)
Definition at line 184 of file math_misc.c.
192 double bk,bkm,bkp,tox;
194 print1(
"!BesselKn: Index n less than 2");
201 bkp = bkm + j*tox*bk;
double BesselK1(double x)
void print1(const char *fmt,...)
double BesselK0(double x)
#define QUIT_PLUTO(e_code)
double RandomNumber |
( |
double |
rmin, |
|
|
double |
rmax |
|
) |
| |
Generate and return a random number between [rmin, rmax]
Definition at line 209 of file math_misc.c.
214 static int first_call = 1;
217 if (first_call == 1){
218 srand(time(NULL) +
prank);
221 eps = (double)(rand())/((
double)RAND_MAX + 1.0);
222 rnd = rmin + eps*(rmax-rmin);
void VectorCartesianComponents |
( |
double * |
v, |
|
|
double |
x1, |
|
|
double |
x2, |
|
|
double |
x3 |
|
) |
| |
Transform the vector
from the chosen coordinate system (= GEOMETRY) to Cartesian components.
- Parameters
-
[in,out] | *v | the original vector. On output v is replaced by the three Cartesian components. |
[in] | x1,x2,x3 | the grid coordinates |
Definition at line 227 of file math_misc.c.
239 double vx1, vx2, vx3;
245 #if GEOMETRY == CARTESIAN
249 #elif GEOMETRY == POLAR
251 EXPAND(
v[0] = vx1*cos(x2) - vx2*sin(x2); ,
252 v[1] = vx1*sin(x2) + vx2*cos(x2); ,
258 EXPAND(v[0] = vx1*sin(x2) + vx2*cos(x2); ,
259 v[1] = vx1*cos(x2) - vx2*sin(x2); ,
262 v[0] = (vx1*sin(x2) + vx2*cos(x2))*cos(x3) - vx3*sin(x3);
263 v[1] = (vx1*sin(x2) + vx2*cos(x2))*sin(x3) + vx3*cos(x3);
264 v[2] = (vx1*cos(x2) - vx2*sin(x2));