PDA

View Full Version : Problems with Gaussfit



green12
10-04-2009, 01:38 PM
Why does result return all errors?
Why does the array coe only have 3 elements instead of 6?



PRO TEST2
x = FINDGEN(100)/100
y = 2*EXP(-(((x-3)/4)^2)/2) +4 +2*x+2*x*x
result = GAUSSFIT(x, y , coe)
plot,x,y
oplot,x,result
print,coe
info,coe
info,result
print,result
END

Thanks a lot!

rwagner
10-06-2009, 01:47 PM
Hi Green12,
I'm sorry to hear that this isn't working for you. Try the following example:






function f, m
x = findgen(100)/100.
y = 2.*exp(-(((x-3.)/4.)^2.)/2.) + 4. + 2.*x + 2.*x*x
s = size(m, /dimensions)
ret = fltarr(s(0))
for j=0L, s(0)-1 do begin
i = m(j,*)
y2 = i(0) * exp(-(((x-i(1))/i(2))^2.)/2.) + i(3) + i(4)*x + i(5)*x*x
d = (y-y2)
d = d*d
d = sum(d)
ret(j) = sqrt(d)
endfor
return, ret
end

m = minimize('f', fltarr(6), fltarr(6)+100., fltarr(6)+1., 100000.)