I am trying to fit a decaying exponential function of the form: A1 - A1exp(-x/A2) to a set of (x,y) values with error bars on y values. I am using the IDL MPFIT function to perform this non linear fit.
function gfunct, xsig, A
return, A[0] - A[0]*exp(-xsig/A[1])
end
pro makeit
xsig=[0d0,4d0,12d0,48d0]
ysig=[0d0,19d0,30d0,36d0]
err=dblarr(1,4)
err[0]=0.000001d0
err[1]=0.5d0*0.4219d0*19d0
err[2]=0.5d0*0.2154d0*30d0
err[3]=0.5d0*0.1279d0*36d0
A = [39d0,10.96d0]
result = MPFITFUN('gfunct', xsig, ysig, err, start)
end
But this code gives me an error:
MPFITFUN: ERROR: must pass parameters in P or PARINFO
Can someone help me identify the correct syntax for the function block? I tried using svdfit but it cannot be used for a function like this, with A[1] in the exponential. Thanks!
The calling sequence for MPFITFUN is
parms = MPFITFUN(MYFUNCT, X, Y, ERR, start_params, ...);
This means you should call it like this:
result = MPFITFUN('gfunct', xsig, ysig, err, A)
Since "A" contains your initial guesses.