comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Voigt function fit using MPFIT
items: Re: Voigt function fit using MPFIT

Voigt function fit using MPFIT
type: item
description: Hi, I have a set of observed data of flux vs wavelength.I am trying MPFIT to fit a voigt function. I defined the function as FUNCTION fit,p,X=x2,Y=nflux2 model=double((voigt(p[0],p[1])*1e-13)/(p[3]*sqrt(!pi))) return,(Y-model)/err END But when I run this, the following errors are coming FUNCTION fit,x2=X,nflux2=Y,p ^ % Programs can't be compiled from single statement mode. return,(Y-model)/1 ^ % Syntax error. Why is this happening?
creator: Sreelakshmi S
date: 2013-10-02T11:12:55-00:00

Re: Voigt function fit using MPFIT
type: item
description: On Wednesday, October 2, 2013 1:12:55 PM UTC+2, Sreelakshmi S wrote: > Hi, > > > > I have a set of observed data of flux vs wavelength.I am trying MPFIT to fit a voigt function. I defined the function as > > > > FUNCTION fit,p,X=x2,Y=nflux2 > > > > model=double((voigt(p[0],p[1])*1e-13)/(p[3]*sqrt(!pi))) > > return,(Y-model)/err > > > > END > > > > But when I run this, the following errors are coming > > > > FUNCTION fit,x2=X,nflux2=Y,p > > ^ > > % Programs can't be compiled from single statement mode. > > > > > > return,(Y-model)/1 > > ^ > > % Syntax error. > > > > Why is this happening? Well, there are a number of things wrong. 1) If you define the function with FUNCTION Fit, Y=nFlux2 then you must use nFlux2 in your code, not Y. Try making a function like this: FUNCTION Fit, Y=nFlux2 PRINT, (N_ELEMENTS(Y) NE 0)?'Y Exist':'Y does not exist' PRINT, (N_ELEMENTS(nFlux2) NE 0)?'nFlux2 Exist':'nFlux2 does not exist' RETURN, '' END and look at the result of the following commands: print, Fit(Y=5) print, Fit(/Y) print, Fit() print, Fit(nFlux2=5) This way you should learn something about passing variables. 2) How are you calling the function? I have the feeling that this is not happening from inside another program or from within IDL. 3) Are you sure there is no other function named fit? The first line of the function you wrote and the one showed are different. 4) In your Voigt function you use parameters p[0], p[1], p[3]. Is there a reason for skipping [2]? 5) The variable "err" is not defined in the function. This will for sure through an error. (well what should an err variable do anyway!) 6) Passing two scalar values to the function will return a scalar value. Is that what you want? I don't think so... 7) I think that the NASA library has some Voigt fit functions... did you look at those? Regards, Helder
creator: Helder Marchetto
date: 2013-10-02T12:47:00-00:00

Re: Voigt function fit using MPFIT
type: item
description: On Wednesday, October 2, 2013 4:42:55 PM UTC+5:30, Sreelakshmi S wrote: > Hi, > > > > I have a set of observed data of flux vs wavelength.I am trying MPFIT to fit a voigt function. I defined the function as > > > > FUNCTION fit,p,X=x2,Y=nflux2 > > > > model=double((voigt(p[0],p[1])*1e-13)/(p[3]*sqrt(!pi))) > > return,(Y-model)/err > > > > END > > > > But when I run this, the following errors are coming > > > > FUNCTION fit,x2=X,nflux2=Y,p > > ^ > > % Programs can't be compiled from single statement mode. > > > > > > return,(Y-model)/1 > > ^ > > % Syntax error. > > > > Why is this happening? Hi, Thank you for your inputs. I have modified the function as FUNCTION voigtfit,p,x,y,er lambda1=1025.7230 gamma1=1.897e08 f1=2.638e-2 av1=double((gamma1*lambda1*1e-13)/(4*!pi*p[0])) u1=(y/p[0])-(p[1]/p[0]) dop1=double(p[0]/lambda1) phi1=double((voigt(av1,u1)*1e-13)/(dop1*sqrt(!pi))) tau1=double(2.654e-02*p[2]*f1*phi1) model1=double(exp(-tau1)) return,(y-model1)/er END and I am calling this function from IDL as below fac={X:vel,Y:nflux2,ERR:dy} result=double(mpfit('voigtfit',p,functargs=fac)) Now when I run this an error comes % MPFIT: Error detected while calling voigtfit: % MPFIT:Keyword parameter not allowed in call. % MPFIT: Error condition detected. Returning to main level. Which is the keyword here? What is this error?
creator: Sreelakshmi S
date: 2013-10-08T01:39:47-00:00

Re: Voigt function fit using MPFIT
type: item
description: On 2013-10-08 03:39, Sreelakshmi S wrote: > On Wednesday, October 2, 2013 4:42:55 PM UTC+5:30, Sreelakshmi S wrote: >> Hi, >> >> >> >> I have a set of observed data of flux vs wavelength.I am trying MPFIT to fit a voigt function. I defined the function as >> >> >> >> FUNCTION fit,p,X=x2,Y=nflux2 >> >> >> >> model=double((voigt(p[0],p[1])*1e-13)/(p[3]*sqrt(!pi))) >> >> return,(Y-model)/err >> >> >> >> END >> >> >> >> But when I run this, the following errors are coming >> >> >> >> FUNCTION fit,x2=X,nflux2=Y,p >> >> ^ >> >> % Programs can't be compiled from single statement mode. >> >> >> >> >> >> return,(Y-model)/1 >> >> ^ >> >> % Syntax error. >> >> >> >> Why is this happening? > > Hi, > Thank you for your inputs. > I have modified the function as > > FUNCTION voigtfit,p,x,y,er > > lambda1=1025.7230 > gamma1=1.897e08 > f1=2.638e-2 > > av1=double((gamma1*lambda1*1e-13)/(4*!pi*p[0])) > u1=(y/p[0])-(p[1]/p[0]) > dop1=double(p[0]/lambda1) > > phi1=double((voigt(av1,u1)*1e-13)/(dop1*sqrt(!pi))) > tau1=double(2.654e-02*p[2]*f1*phi1) > model1=double(exp(-tau1)) > return,(y-model1)/er > END > > and I am calling this function from IDL as below > > fac={X:vel,Y:nflux2,ERR:dy} > result=double(mpfit('voigtfit',p,functargs=fac)) > > Now when I run this an error comes > % MPFIT: Error detected while calling voigtfit: > % MPFIT:Keyword parameter not allowed in call. > % MPFIT: Error condition detected. Returning to main level. > > Which is the keyword here? What is this error? There are instructions at the beginning of mpfit.pro. They say how the function voightfit (or myfunct, as it is called there) should be defined. It should have a single non-keyword parameter only, the parameter list P. All other parameters must be keyword parameters, corresponding to the parameter list in functargs. So you need something like FUNCTION voigtfit,p,x=x,y=y,er=er The reason you get a "keyword parameter not allowed in call" is that mpfit tries to call voigtfit with the keyword parameters you spec…
creator: Mats Löfdahl
date: 2013-10-08T18:14:23-00:00