core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change
on this file since dcef2ee was
dcef2ee,
checked in by Paul Kienzle <pkienzle@…>, 8 years ago
|
fix opencl build error for pearl necklace
|
-
Property mode set to
100644
|
File size:
887 bytes
|
Rev | Line | |
---|
[dcef2ee] | 1 | int factorial(int f); |
---|
[cf404cb] | 2 | double Si(double x); |
---|
[dcef2ee] | 3 | |
---|
[cf404cb] | 4 | // integral of sin(x)/x: approximated to w/i 1% |
---|
| 5 | double Si(double x) |
---|
| 6 | { |
---|
| 7 | int i; |
---|
| 8 | int nmax=6; |
---|
| 9 | double out; |
---|
| 10 | long power; |
---|
| 11 | double pi = 4.0*atan(1.0); |
---|
| 12 | |
---|
| 13 | if (x >= pi*6.2/4.0){ |
---|
| 14 | double out_sin = 0.0; |
---|
| 15 | double out_cos = 0.0; |
---|
| 16 | out = pi/2.0; |
---|
| 17 | |
---|
| 18 | for (i=0; i<nmax-2; i+=1) { |
---|
| 19 | out_cos += pow(-1.0, i) * (double)factorial(2*i) / pow(x, 2*i+1); |
---|
| 20 | out_sin += pow(-1.0, i) * (double)factorial(2*i+1) / pow(x, 2*i+2); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | out -= cos(x) * out_cos; |
---|
| 24 | out -= sin(x) * out_sin; |
---|
| 25 | return out; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | out = 0.0; |
---|
| 29 | |
---|
| 30 | for (i=0; i<nmax; i+=1) { |
---|
| 31 | if (i==0) { |
---|
| 32 | out += x; |
---|
| 33 | continue; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | power = pow(x,(2 * i + 1)); |
---|
[dcef2ee] | 37 | out += pow(-1.0, i) * power / ((2.0 * (double)i + 1.0) * (double)factorial(2 * i + 1)); |
---|
[cf404cb] | 38 | |
---|
| 39 | //printf ("Si=%g %g %d\n", x, out, i); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | return out; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | int factorial(int f) |
---|
| 46 | { |
---|
| 47 | if ( f == 0 ) |
---|
| 48 | return 1; |
---|
| 49 | return(f * factorial(f - 1)); |
---|
| 50 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.