Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
Hello All, I am trying to use the curvefit algorithm in IDL for fitting my data with a function as given in the code below. It is peacefully fitting and giving me the result, but only one problem, it is doing only one iteration and giving the same A=[] value as the fitted result. I'm not able to figure out what went wrong, and I have used cuurvefit before and it worked well. Do anybody have any idea to solve this issue? Any help is appreciated.... Thanks, Krishnakumar code: RO gfunct, X, A, F, pder F = sqrt((!dpi^5.0 * A[0]^3.0) / (8 * x^5.0)) * exp( - (!dpi^2 * A[0]) / (4*x)) * 180.0 IF N_PARAMS() GE 1 THEN $ ; calculate the partial derivatives...... pder = [!dpi^5.0 * A[0] / (8*x^5.0) * exp(-!dpi^2.0 * A[0] / (4*x)) * 180.0* (1.5 - !dpi^2.0 * A[0]/ (4*x))] END openr,1,"data.dat" xpy=fltarr(3,301) readf,1,xpy x=reform(xpy[1,*]) y=reform(xpy[2,*]) A=[100.0] weights = 1.0/y^2.0 yfit=curvefit(x+10,y,weights,A,SIGMA,chisq=chisq,iter=it,fun ction_name='gfunct') print,A,sigma,chisq,it close,1 plot,x,yfit oplot,x,y end
Hello Krishnakumar, please doublecheck the partial derivative. Your function is F(A) = const * G(A) with const = 180 * SQRT(!dpi^5/(8*x^5)) So your partial derivative should be dF(A)/dA = const * dG(A)/dA The SQRT seems to be missing in your derivative. HTH, Heinz
On Tuesday, December 9, 2014 3:54:52 AM UTC-5, Heinz Stege wrote: > please doublecheck the partial derivative. That's why MPFIT now has a partial derivative checker for debugging. It's so hard to get right! Craig
On Tuesday, December 9, 2014 2:24:52 PM UTC+5:30, Heinz Stege wrote: > Hello Krishnakumar, > > please doublecheck the partial derivative. > > Your function is > F(A) = const * G(A) > with > const = 180 * SQRT(!dpi^5/(8*x^5)) > So your partial derivative should be > dF(A)/dA = const * dG(A)/dA > The SQRT seems to be missing in your derivative. > > HTH, Heinz Thanks Heinz. That was a silly mistake I did not notice. Now the code is working. Krishnakumar