# Linear function with minuit

Hello, I am sorry for the bother.
I am trying to learn Minuit so I want to fit a simple linear function y=mx+q
This is my code (in Fortran), do you know why I cannot get the right value of the parameters?

PROGRAM TEST
IMPLICIT NONE

``````  real*8 y_o(3), x_o(3), erry_o(3)
real*8 para(2),chi, chi2
external FNC
common/paramfit/para,chi2

open(unit=5,file='minuit_param.dat',status='old')
open(unit=6,file='minuit_out.dat', form='formatted')
``````

c open(unit=7, file=‘results.dat’,status=‘new’)

``````    x_o(1)=1.575
x_o(2)=1.606
x_o(3)=1.744
y_o(1)=1.053
y_o(2)=1.131
y_o(3)=1.292
erry_o(1)=0.1
erry_o(2)=0.2
erry_o(3)=0.15

call mintio(5,6,7)

call minuit(FNC,0)

close(5)
close(6)

STOP
END

SUBROUTINE FNC(npar,grd, chi, xv, iflg, fut)

real*8 m, x, y, q
real*8 y_o(3), x_o(3), erry_o(3)
real*8 grd(*), xv(*)
real*8 w,fut, funz
integer npar, iflg
real*8 para(2),chi, chi2
external funz
common/paramfit/para,chi2

npar=2

do i=1,2
para(i)=xv(i)
end do
``````

c Computation of the Chi Square

``````  w=0.d0

do j=1,3
w=w+((y_o(j)-funz(x_o(j)))**2/(funz(x_o(j))))
end do
chi=w
chi2=chi
RETURN
END

real*8 function funz(x)
real*8 x,m,q
real*8 para(2),chi, chi2
common/paramfit/para,chi2

m=para(1)
q=para(2)
funz=m*x+q

RETURN
END
``````

This is the output I get:

MINUIT RELEASE 96.03 INITIALIZED. DIMENSIONS 100/ 50 EPSMAC= 0.89E-15

``````                      MINUIT DATA BLOCK NO.   1
``````

Chi Square

PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 'm ’ 1.0000 0.10000E-01 -5.0000 5.0000
2 'q ’ -2.0000 0.10000E-01 -5.0000 5.0000
***************************************************************************

MINUIT: FIRST CALL TO USER FUNCTION, WITH IFLAG=1

FCN= -5.261639 FROM PARAMETR STATUS=RESET 2 CALLS 2 TOTAL
EDM= unknown STRATEGY= 1 NO ERROR MATRIX

EXT PARAMETER CURRENT GUESS PHYSICAL LIMITS
NO. NAME VALUE ERROR NEGATIVE POSITIVE
1 m 1.0000 0.10000E-01 -5.0000 5.0000
2 q -2.0000 0.10000E-01 -5.0000 5.0000

** 1 **SET PRINT

** 2 **SET ERR 0.5000

MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
MINUIT WARNING IN HESSE
============== Second derivative zero for parameter 1
MNHESS FAILS AND WILL RETURN DIAGONAL MATRIX.

FCN= -15.13724 FROM MIGRAD STATUS=CONVERGED 93 CALLS 95 TOTAL
EDM= 0.19E-06 STRATEGY=1 ERROR MATRIX UNCERTAINTY=100.0%

EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 m 1.0000 4.1223 -0.0000 0.0000
2 q -4.9529 2.2768 0.43940E-01 -0.17457E-02
ERR DEF= 0.500

** 4 **STOP

CALL TO USER FUNCTION WITH IFLAG = 3

…MINUIT TERMINATED BY MINUIT COMMAND: STOP

May be you can find some help here.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.