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