본문 바로가기
my research

2D Fit

by 녕아 2013. 5. 27.


How to fit 2-D vectors in PAW ?


Here is an example showing how to proceed:

 MACRO FIT2D
 *
 * Macro to test 2-D fits of functions F(x1,x2) = Y to data.
 *
 ZONE 2 2
 OPT NSTA

 H/DEL *
 VECT/DEL *

 NP= 3
 VECT/CREA PAR([NP])  R 100.0 1.0 1.0
 VECT/CREA STEP([NP]) R 1.0 1.0 1.0
 VECT/CREA PMIN([NP]) R 1.0 0.0 1.0
 VECT/CREA PMAX([NP]) R 1.0 1.0 1.0
 *
 * Define number of bins in X and Y, then book vectors:
 *
 NX= 6
 NY= 8
 MINX=  0.0
 MAXX=  3.0
 MINY=  0.0
 MAXY=  4.0
 N= [NX]*[NY]
 VECT/CREA Y([N])
 VECT/CREA EY([N])
 VECT/CREA X([N],2)
 *
 * Make dummy data using random function HRNDM2. Observe that here the values to
 * be expected from the fits are defined:
 *                    |          |
 FUN2 20 EXP(-0.5*(((1.5-X)**2+(2.0-Y)**2)/(3.**2))) 20 [MINX] [MAXX] _
 20 [MINY] [MAXY]
 2D 30 'DATA'  [NX] [MINX] [MAXX] [NY] [MINY] [MAXY]
 APPLICATION COMIS QUIT
       SUBROUTINE RNDM
       DO 10 I=1,10000
         CALL HRNDM2(20,RX,RY)
         CALL HFILL(30,RX,RY,1.0)
  10   CONTINUE
       END
       CALL RNDM
       END
 QUIT
 H/PL 30 LEGO
 GET/CON 30 Y
 GET/ERR 30 EY
 *
 * Put coordinates x1 and x2 into vector X:
 *
 BINWX= ([MAXX]-[MINX])/[NX]
 BINWY= ([MAXY]-[MINY])/[NY]
 DO I=1,[NY]
   DO J=1,[NX]
     ZX= $SIGMA( [MINX]+[BINWX]*([J]-0.5) )
     ZY= $SIGMA( [MINY]+[BINWY]*([I]-0.5) )
     N= $SIGMA( ([I]-1)*[NX]+[J] )
     VECT/INP X([N],1) [ZX]
     VECT/INP X([N],2) [ZY]
   ENDDO
 ENDDO
 *
 * Do the fit:
 *
 V/IN PAR 100.0 1.0 1.0
 V/FIT X Y EY FUNXY.FOR 0 [NP] PAR STEP PMIN PMAX

 | Plot result:
 P1= PAR(1)
 P2= PAR(2)
 P3= PAR(3)
 ZONE 1 2 2 S
 FUN2 50 [P1]*EXP(-0.5*((([P2]-X)**2+([P3]-Y)**2)/(3.**2))) [NX] [MINX] [MAXX] _
 [NY] [MINY] [MAXY] ' '
 H/PL 50 LEGO

 RETURN
 

Where the COMIS function FUNXY.FOR is:

       FUNCTION FUNXY(X)
       DIMENSION X(2)
       COMMON/PAWPAR/PAR(3)
       FUNXY= PAR(1)
      &      *EXP( -0.5*(((PAR(2)-X(1))**2+(PAR(3)-X(2))**2)/(3.**2)) )
       END
 
    PAW > exe fit2d

********************************************** * * * Function minimization by SUBROUTINE HFITV * * Variable-metric method * * ID = 0 CHOPT = 0 * * * ********************************************** Convergence when estimated distance to minimum (EDM) .LT. 0.10E+01 FCN= 44.38704 FROM MIGRAD STATUS=CONVERGED 70 CALLS 71 TOTAL EDM= 0.92E-04 STRATEGY= 1 ERROR MATRIX ACCURATE EXT PARAMETER STEP FIRST NO. NAME VALUE ERROR SIZE DERIVATIVE 1 P1 232.45 2.4176 0.58806 0.23439E-04 2 P2 1.7379 0.10665 0.24700E-01 0.10854 3 P3 2.0745 0.81073E-01 0.19395E-01 -0.86093E-01 CHISQUARE = 0.9864E+00 NPFIT = 48 PAW >

      
    



















'my research' 카테고리의 다른 글

2D Fit  (0) 2013.05.27

댓글0