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 4a96b8b was
08648c0,
checked in by Jae Cho <jhjcho@…>, 13 years ago
|
more s king's fractal models: todo: doc, test
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Line | |
---|
1 | // by jcho |
---|
2 | #include <math.h> |
---|
3 | #include "libmultifunc/libfunc.h" |
---|
4 | #include <stdio.h> |
---|
5 | |
---|
6 | //used in Si func |
---|
7 | int factorial(int i) |
---|
8 | { |
---|
9 | int k, j; |
---|
10 | if (i<2){ |
---|
11 | return 1; |
---|
12 | } |
---|
13 | k=1; |
---|
14 | for(j=1;j<i;j++) |
---|
15 | { |
---|
16 | k=k*(j+1); |
---|
17 | } |
---|
18 | return k; |
---|
19 | } |
---|
20 | |
---|
21 | // Used in pearl nec model |
---|
22 | // Sine integral function: approximated within 1%!!! |
---|
23 | // integral of sin(x)/x up to namx term nmax=6 looks the best. |
---|
24 | double Si(double x) |
---|
25 | { |
---|
26 | int i; |
---|
27 | int nmax=6; |
---|
28 | double out; |
---|
29 | long double power; |
---|
30 | double pi = 4.0*atan(1.0); |
---|
31 | if (x >= pi*6.2/4.0){ |
---|
32 | |
---|
33 | double out_sin = 0.0; |
---|
34 | double out_cos = 0.0; |
---|
35 | out = pi/2.0; |
---|
36 | for (i=0; i<nmax-2; i+=1){ |
---|
37 | out_cos += pow(-1.0, i) * (double)factorial(2*i) / pow(x, 2*i+1); |
---|
38 | out_sin += pow(-1.0, i) * (double)factorial(2*i+1) / pow(x, 2*i+2); |
---|
39 | } |
---|
40 | out -= cos(x) * out_cos; |
---|
41 | out -= sin(x) * out_sin; |
---|
42 | return out; |
---|
43 | } |
---|
44 | out = 0.0; |
---|
45 | for (i=0; i<nmax; i+=1) |
---|
46 | { |
---|
47 | if (i==0){ |
---|
48 | out += x; |
---|
49 | continue; |
---|
50 | } |
---|
51 | power = pow(x,(2 * i + 1)); |
---|
52 | out += (double)pow(-1, i) * power / ((2.0 * (double)i + 1.0) * (double)factorial(2 * i + 1)); |
---|
53 | //printf ("Si=%g %g %d\n", x, out, i); |
---|
54 | } |
---|
55 | return out; |
---|
56 | } |
---|
57 | |
---|
58 | double sinc(double x) |
---|
59 | { |
---|
60 | if (x==0.0){ |
---|
61 | return 1.0; |
---|
62 | } |
---|
63 | return sin(x)/x; |
---|
64 | } |
---|
65 | |
---|
66 | double gamln(double xx) { |
---|
67 | |
---|
68 | double x,y,tmp,ser; |
---|
69 | static double cof[6]={76.18009172947146,-86.50532032941677, |
---|
70 | 24.01409824083091,-1.231739572450155, |
---|
71 | 0.1208650973866179e-2,-0.5395239384953e-5}; |
---|
72 | int j; |
---|
73 | |
---|
74 | y=x=xx; |
---|
75 | tmp=x+5.5; |
---|
76 | tmp -= (x+0.5)*log(tmp); |
---|
77 | ser=1.000000000190015; |
---|
78 | for (j=0;j<=5;j++) ser += cof[j]/++y; |
---|
79 | return -tmp+log(2.5066282746310005*ser/x); |
---|
80 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.