Greetings. I'm trying to understand how Craig
Markwardt's peak fitting function MPFIT2DPEAK
works when you wish to require that certain
parameters be held constant.
Specifically, I know that my data should peak
at the origin and so I'd like to force the
fitted Gaussian to peak there as well.
Despite specifying that A[4] and A[5] be
fixed using the PARINFO structure, the fitted
Gaussian is not centered at the origin.
Supplying PARINFO to MPFIT2DPEAK does change
the fit but it actually makes it slighly worse.
Anyone know what I might be doing wrong?
Here's my sample code:
;------------------------------------------------
; Construct a sample gaussian surface in range [-5,5] centered at
[0,0]
x = findgen(100)*0.1 - 5. & y = x
xx = x # (y*0 + 1)
yy = (x*0 + 1) # y
rr = sqrt((xx-0*2.)^2 + (yy+0*3.)^2)
; Gaussian surface with sigma=0.5, peak value of 3, noise with
sigma=0.2
seed=6
z = 3.*exp(-(rr/0.5)^2) + randomn(seed,100,100)*.2
pi = replicate({value:0.D, fixed:0, limited:[0,0], $
limits:[0.D,0]}, 7)
pi(4).fixed = 1
pi(5).fixed = 1
a0=[0., 3., 1.0, 1.0, 0.0, 0.0, 0.0]
pi(*).value = a0
; Fit gaussian parameters A
zfit = mpfit2dpeak(z, a1, x, y, /tilt, PARINFO=pi)
zfit = mpfit2dpeak(z, a2, x, y, /tilt)
print,a1
print,a2
------------------------------------------------
IDL prints:
a1=[-0.000156282, 2.82180, 0.382853, 0.347286, -0.0999999, 0.0999999,
0.716917]
a2=[-0.000266513, 3.06073, 0.345753, 0.351519, -0.000407959,
0.00455947, 1.98130]
|