source: Sophya/trunk/SophyaPI/PIext/userfitfunex.c@ 4037

Last change on this file since 4037 was 385, checked in by ercodmgr, 26 years ago

user function for fit cmv 13/8/99

File size: 2.3 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <math.h>
4
5/********************************************************************/
6/* fonction de fit "f(x;h,x0,sig,c) = h*exp(-0.5*((x-x0)/sig)^2)+c" */
7/* avec nvar=1 npar=4 */
8/* x = x[0] */
9/* p[0]=h, p[1]=x0, p[2]=sig, p[3]=c */
10/********************************************************************/
11double gauss1(double const* x,double const* p)
12{
13double xc;
14xc = (x[0]-p[1])/p[2]; xc *= -xc/2.;
15return((xc>=-80.) ? p[0]*exp(xc)+p[3] : p[3]);
16}
17
18/* la definition de cette fonction n'est pas obligatoire */
19/* dp[0] = df(x;h,x0,sig,c)/dh, dp[1] = etc... */
20double gauss1_der(double const* x,double const* p,double* dp)
21{
22double xc,xc2,e,f;
23xc = (x[0]-p[1])/p[2];
24xc2 = xc*xc;
25e = -xc2/2.;
26if(e>=-80.) e = exp(e); else e = 0.;
27f = p[0]*e;
28dp[0] = e;
29dp[1] = xc / p[2] *f;
30dp[2] = xc2 / p[2] *f;
31dp[3] = 1.;
32return(f+p[3]);
33}
34
35/********************************************************/
36/* fonction de fit gaussienne 2D avec correlation */
37/* f(x,y;h,x0,y0,sx,sy,rho,c) = */
38/* h * exp{ -0.5*[ (x-x0)^2/sx^2 + (y-y0)^2/s^2 */
39/* -2*rho*(x-x0)*(y-y0)/(sx*sy) ]} */
40/* avec nvar=2 npar=7 */
41/* x = x[0] et y=x[2] */
42/* p[0]=h, p[1]=x0, p[2]=y0 */
43/* p[3]=sx, p[4]=sy, p[5]=rho, p[6]=fond */
44/********************************************************/
45double gauss2(double const* x,double const* p)
46{
47double ax,ay,a;
48ax = (x[0]-p[1])/p[3];
49ay = (x[1]-p[2])/p[4];
50a = -(ax*ax+ay*ay-2.*p[5]*ax*ay)/2.;
51return((a>=-80.) ? p[0]*exp(a)+p[6] : p[6]);
52}
53
54/* la definition de cette fonction n'est pas obligatoire */
55/* dp[0] = f(x,y;h,x0,y0,sx,sy,rho,c)/dh, dp[1] = etc... */
56double gauss2_der(double const* x,double const* p,double* dp)
57{
58double ax,ay,a,p0ea;
59ax = (x[0]-p[1])/p[3];
60ay = (x[1]-p[2])/p[4];
61a = -(ax*ax+ay*ay-2.*p[5]*ax*ay)/2.;
62p0ea = (a>=-80.) ? exp(a) : 0.;
63dp[0] = p0ea;
64 p0ea *= p[0];
65dp[1] = (ax-p[5]*ay)/p[3] *p0ea;
66dp[2] = (ay-p[5]*ax)/p[4] *p0ea;
67dp[3] = ax*dp[1];
68dp[4] = ay*dp[2];
69dp[5] = ax*ay *p0ea;
70dp[6] = 1.;
71return(p0ea+p[6]);
72}
Note: See TracBrowser for help on using the repository browser.