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