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 | */ |
---|
23 | double 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 | return pars->scale * pow(zz,zz) * pow(R,z) * exp(-1*R*zz)/((pars->center) * tgamma(zz)) ; |
---|
28 | } |
---|
29 | |
---|
30 | /** |
---|
31 | * Function to evaluate 2D schulz function |
---|
32 | * The function is normalized to the 'scale' parameter. |
---|
33 | * |
---|
34 | * f(x,y) = Schulz(x) * Schulz(y) |
---|
35 | * |
---|
36 | * where both Shulzs share the same parameters. |
---|
37 | * |
---|
38 | * @param pars: parameters of the schulz |
---|
39 | * @param x: x-value |
---|
40 | * @param y: y-value |
---|
41 | * @return: function value |
---|
42 | */ |
---|
43 | double schulz_analytical_2DXY(SchulzParameters *pars, double x, double y) { |
---|
44 | return schulz_analytical_1D(pars, x) * schulz_analytical_1D(pars, y); |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * Function to evaluate 2D Schulz function |
---|
49 | * The function is normalized to the 'scale' parameter. |
---|
50 | * |
---|
51 | * f(x,y) = Schulz(x) * Schulz(y) |
---|
52 | * |
---|
53 | * where both Gaussians share the same parameters. |
---|
54 | * |
---|
55 | * @param pars: parameters of the gaussian |
---|
56 | * @param length: length of the (x,y) vector |
---|
57 | * @param phi: angle relative to x |
---|
58 | * @return: function value |
---|
59 | */ |
---|
60 | double schulz_analytical_2D(SchulzParameters *pars, double length, double phi) { |
---|
61 | return schulz_analytical_2DXY(pars, length*cos(phi), length*sin(phi)); |
---|
62 | } |
---|