ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change
on this file since 8c8cb05 was
8c8cb05,
checked in by Jae Cho <jhjcho@…>, 13 years ago
|
new model pre.
|
-
Property mode set to
100644
|
File size:
825 bytes
|
Line | |
---|
1 | #include <math.h> |
---|
2 | #include "libmultifunc/libfunc.h" |
---|
3 | #include <stdio.h> |
---|
4 | |
---|
5 | //used in Si func |
---|
6 | int factorial(int i) |
---|
7 | { |
---|
8 | int k, j; |
---|
9 | if (i<2){ |
---|
10 | return 1; |
---|
11 | } |
---|
12 | k=1; |
---|
13 | for(j=1;j<i;j++) |
---|
14 | { |
---|
15 | k=k*(j+1); |
---|
16 | } |
---|
17 | return k; |
---|
18 | } |
---|
19 | |
---|
20 | // Used in pearl nec model |
---|
21 | //integral of sin(x)/x up to namx term nmax>10 looks fine. |
---|
22 | double Si(double x, int nmax ) |
---|
23 | { |
---|
24 | int i; |
---|
25 | double out; |
---|
26 | long double power; |
---|
27 | if (x > 5.0){ |
---|
28 | double pi = 4.0*atan(1.0); |
---|
29 | return pi/2.0; |
---|
30 | } |
---|
31 | out = 0.0; |
---|
32 | for (i=0; i<nmax; i+=1) |
---|
33 | { |
---|
34 | if (i==0){ |
---|
35 | out += x; |
---|
36 | continue; |
---|
37 | } |
---|
38 | power = pow(x,(2 * i + 1)); |
---|
39 | out += (double)pow(-1, i) * power / ((2.0 * (double)i + 1.0) * (double)factorial(2 * i + 1)); |
---|
40 | //printf ("Si=%g %g %d\n", x, out, i); |
---|
41 | } |
---|
42 | return out; |
---|
43 | } |
---|
44 | |
---|
45 | double sin_x(double x) |
---|
46 | { |
---|
47 | if (x==0){ |
---|
48 | return 1.0; |
---|
49 | } |
---|
50 | return sin(x)/x; |
---|
51 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.