Constraint on a dependent variables in FuncFit
Jonpope
I'm currently a script to attempt a two dimensional Voigt fit, however I need to place constraints (0<=x<=1) on one of the dependent variables within the fit, specifically w[0] in the FitVoigt2D function which determines the ratio of Gaussian/Lorentzian mixing. So far I have played around with making a constraint text wave and using the /c flag for FuncFitMD without success.
Is there a way to place a constraint on one particular value in a wave? Or, as I suspect is there a more efficient way of fitting to a two dimensional Voigt that has already been written?
Regards
Jon
Function Voigt2D(thewave)
Wave thewave
Variable/g Base,GaussianFraction,PeakHeight,xOffset,xFWHM,yOffset,yFWHM,kSix
String GaussianRatio
Make/o/d/n=8 Voigt_Coef
GaussianFraction=0.5
Voigt_Coef[0]=GaussianFraction
Voigt_Coef[1]=Base
Voigt_Coef[2]=PeakHeight
Voigt_Coef[3]=xOffset
Voigt_Coef[4]=xFWHM
Voigt_Coef[5]=yOffset
Voigt_Coef[6]=yFWHM
Voigt_Coef[7]=kSix
FuncFitMD/q FitVoigt2D, Voigt_Coef, thewave
End
Function FitVoigt2D(w,x,y) : FitFunc
Wave w
Variable x,y
Return w[1]+(w[0]*(w[2]*exp((-1/(2*(1-(w[7]*w[7]))))*((((x-w[3])/w[4])^2)+(((y-w[5])/w[6])^2)-((2*w[7]*(x-w[3])*(y-w[5]))/(w[4]*w[6]))))))+((1-w[0])*(w[2]/(1+(((x-w[3])/w[4])^2)+(((y-w[5])/w[6])^2))))
End
Wave thewave
Variable/g Base,GaussianFraction,PeakHeight,xOffset,xFWHM,yOffset,yFWHM,kSix
String GaussianRatio
Make/o/d/n=8 Voigt_Coef
GaussianFraction=0.5
Voigt_Coef[0]=GaussianFraction
Voigt_Coef[1]=Base
Voigt_Coef[2]=PeakHeight
Voigt_Coef[3]=xOffset
Voigt_Coef[4]=xFWHM
Voigt_Coef[5]=yOffset
Voigt_Coef[6]=yFWHM
Voigt_Coef[7]=kSix
FuncFitMD/q FitVoigt2D, Voigt_Coef, thewave
End
Function FitVoigt2D(w,x,y) : FitFunc
Wave w
Variable x,y
Return w[1]+(w[0]*(w[2]*exp((-1/(2*(1-(w[7]*w[7]))))*((((x-w[3])/w[4])^2)+(((y-w[5])/w[6])^2)-((2*w[7]*(x-w[3])*(y-w[5]))/(w[4]*w[6]))))))+((1-w[0])*(w[2]/(1+(((x-w[3])/w[4])^2)+(((y-w[5])/w[6])^2))))
End
Assuming you really mean a fit coefficient, then constraint text wave would seem like the correct approach. What did you try? What went wrong?
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
July 24, 2013 at 10:46 am - Permalink
You're right I was referring to a fit coefficient, have displayed an attempt below, which generates the following error message:
In addition to this I made the 'GaussianFraction' variable global, constrained it and attempted to place it within the formula returned from FitVoigt2D(), which changed all of the outputted values to zero.
Regards
Jon
Wave thewave
Variable/g Base,GaussianFraction,PeakHeight,xOffset,xFWHM,yOffset,yFWHM,kSix
String GaussianRatio
Make/o/d/n=8 Voigt_Coef
GaussianFraction=0.5
Voigt_Coef[0]=GaussianFraction
Voigt_Coef[1]=Base
Voigt_Coef[2]=PeakHeight
Voigt_Coef[3]=xOffset
Voigt_Coef[4]=xFWHM
Voigt_Coef[5]=yOffset
Voigt_Coef[6]=yFWHM
Voigt_Coef[7]=kSix
Make/o/t/n=1 T_constraints
T_constraints[0]= {"w[0]<0.99999","w[0]>0.00001"}
FuncFitMD/q FitVoigt2D, Voigt_Coef, thewave /C=T_constraints
End
Function FitVoigt2D(w,x,y) : FitFunc
Wave w
Variable x,y
Return w[1]+(w[0]*(w[2]*exp((-1/(2*(1-(w[7]*w[7]))))*((((x-w[3])/w[4])^2)+(((y-w[5])/w[6])^2)-((2*w[7]*(x-w[3])*(y-w[5]))/(w[4]*w[6]))))))+((1-w[0])*(w[2]/(1+(((x-w[3])/w[4])^2)+(((y-w[5])/w[6])^2))))
End
<iIgor>
July 26, 2013 at 09:51 am - Permalink
T_constraints[0]= {"w[0]<0.99999","w[0]>0.00001"}
toT_constraints[0]= {"K0<0.99999","K0>0.00001"}
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
July 26, 2013 at 04:09 pm - Permalink
August 9, 2013 at 02:50 pm - Permalink