source: sasview/sansmodels/src/sans/models/c_extensions/schulz.c @ 20f00bed

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 20f00bed was c5607fa, checked in by Jae Cho <jhjcho@…>, 15 years ago

Trick applied to the formula of Schulz func to fix having many singularities near small sigmas

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 * Schulz function
3 */
4
5#include "schulz.h"
6#include <math.h>
7#include <stdio.h>
8#include <stdlib.h>
9
10
11/**
12 * Function to evaluate 1D Schulz function.
13 * The function is normalized to the 'scale' parameter.
14 *
15 * f(x)=scale * math.pow(z+1, z+1)*math.pow((R), z)*
16 *                                      math.exp(-R*(z+1))/(center*gamma(z+1)
17 *              z= math.pow[(1/(sigma/center),2]-1
18 *              R= x/center
19 * @param pars: parameters of the schulz
20 * @param x: x-value
21 * @return: function value
22 */
23double schulz_analytical_1D(SchulzParameters *pars, double x) {
24        double z = pow(pars->center/ pars->sigma, 2)-1;
25        double R= x/pars->center;
26        double zz= z+1;
27        double expo;
28        expo = log(pars->scale)+zz*log(zz)+z*log(R)-R*zz-log(pars->center)-lgamma(zz);
29
30        return exp(expo);//pars->scale * pow(zz,zz) * pow(R,z) * exp(-1*R*zz)/((pars->center) * tgamma(zz)) ;
31}
32
33/**
34 * Function to evaluate 2D schulz function
35 * The function is normalized to the 'scale' parameter.
36 *
37 * f(x,y) = Schulz(x) * Schulz(y)
38 *
39 * where both Shulzs share the same parameters.
40 *
41 * @param pars: parameters of the schulz
42 * @param x: x-value
43 * @param y: y-value
44 * @return: function value
45 */
46double schulz_analytical_2DXY(SchulzParameters *pars, double x, double y) {
47    return schulz_analytical_1D(pars, x) * schulz_analytical_1D(pars, y);
48}
49
50/**
51 * Function to evaluate 2D Schulz  function
52 * The function is normalized to the 'scale' parameter.
53 *
54 * f(x,y) = Schulz(x) * Schulz(y)
55 *
56 * where both Gaussians share the same parameters.
57 *
58 * @param pars: parameters of the gaussian
59 * @param length: length of the (x,y) vector
60 * @param phi: angle relative to x
61 * @return: function value
62 */
63double schulz_analytical_2D(SchulzParameters *pars, double length, double phi) {
64    return schulz_analytical_2DXY(pars, length*cos(phi), length*sin(phi));
65}
Note: See TracBrowser for help on using the repository browser.