Changeset 0da2a01 in sasmodels for sasmodels/models/lib


Ignore:
Timestamp:
Jan 21, 2016 4:19:48 PM (8 years ago)
Author:
krzywon
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
7d256c8
Parents:
0420af7 (diff), 790bcc4c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'origin/master'

Location:
sasmodels/models/lib
Files:
1 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/lib/Si.c

    rdcef2ee r0420af7  
    1 int factorial(int f); 
    21double Si(double x); 
    32 
    4 // integral of sin(x)/x: approximated to w/i 1% 
     3// integral of sin(x)/x Taylor series approximated to w/i 0.1% 
    54double Si(double x) 
    65{ 
    76        int i; 
    8         int nmax=6; 
     7        int nmax=10; 
    98        double out; 
    109        long power; 
     
    1615                out = pi/2.0; 
    1716 
    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                 } 
     17                // Explicitly writing factorial values triples the speed of the calculation 
     18                out_cos = 1/x - 2/pow(x,3) + 24/pow(x,5) - 720/pow(x,7) + 40320/pow(x,9); 
     19                out_sin = 1/x - 6/pow(x,4) + 120/pow(x,6) - 5040/pow(x,8) + 362880/pow(x,10); 
    2220 
    2321                out -= cos(x) * out_cos; 
     
    2624        } 
    2725 
    28         out = 0.0; 
     26        // Explicitly writing factorial values triples the speed of the calculation 
     27        out = x - pow(x, 3)/18 + pow(x,5)/600 - pow(x,7)/35280 + pow(x,9)/3265920; 
    2928 
    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)); 
    37                 out += pow(-1.0, i) * power / ((2.0 * (double)i + 1.0) * (double)factorial(2 * i + 1)); 
    38  
    39                 //printf ("Si=%g %g %d\n", x, out, i); 
    40         } 
    41  
     29        //printf ("Si=%g %g\n", x, out); 
    4230        return out; 
    4331} 
    44  
    45 int factorial(int f) 
    46 { 
    47     if ( f == 0 )  
    48         return 1; 
    49     return(f * factorial(f - 1)); 
    50 } 
Note: See TracChangeset for help on using the changeset viewer.