source: sasview/sansmodels/src/sans/models/c_extensions/gaussian.c @ 17a6843

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 17a6843 was ae3ce4e, checked in by Mathieu Doucet <doucetm@…>, 17 years ago

Moving sansmodels to trunk

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * Gaussian function
3 */
4
5#include "gaussian.h"
6#include <math.h>
7#include <stdio.h>
8#include <stdlib.h>
9
10
11/**
12 * Function to evaluate 1D Gaussian function.
13 * The function is normalized to the 'scale' parameter.
14 *
15 * f(x)=scale * 1/(sigma^2*2pi)e^(-(x-mu)^2/2sigma^2)
16 *
17 * @param pars: parameters of the gaussian
18 * @param x: x-value
19 * @return: function value
20 */
21double gaussian_analytical_1D(GaussianParameters *pars, double x) {
22        double sigma2 = pow(pars->sigma, 2);   
23        return pars->scale / sigma2 * exp( -pow((x-pars->center), 2) / (2*sigma2));
24}
25
26/**
27 * Function to evaluate 2D Gaussian  function
28 * The function is normalized to the 'scale' parameter.
29 *
30 * f(x,y) = Gaussian(x) * Gaussian(y)
31 *
32 * where both Gaussians share the same parameters.
33 *
34 * @param pars: parameters of the gaussian
35 * @param x: x-value
36 * @param y: y-value
37 * @return: function value
38 */
39double gaussian_analytical_2DXY(GaussianParameters *pars, double x, double y) {
40    return gaussian_analytical_1D(pars, x) * gaussian_analytical_1D(pars, y);
41} 
42
43/**
44 * Function to evaluate 2D Gaussian  function
45 * The function is normalized to the 'scale' parameter.
46 *
47 * f(x,y) = Gaussian(x) * Gaussian(y)
48 *
49 * where both Gaussians share the same parameters.
50 *
51 * @param pars: parameters of the gaussian
52 * @param length: length of the (x,y) vector
53 * @param phi: angle relative to x
54 * @return: function value
55 */
56double gaussian_analytical_2D(GaussianParameters *pars, double length, double phi) {
57    return gaussian_analytical_2DXY(pars, length*cos(phi), length*sin(phi));
58} 
Note: See TracBrowser for help on using the repository browser.