Constraint on a dependent variables in FuncFit

Hello

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
It sounds like you are misusing "dependent variable". I think you mean "fit coefficient". A dependent variable is the Y data you are attempting to model.

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
Hi John

You're right I was referring to a fit coefficient, have displayed an attempt below, which generates the following error message:


While executing FuncFItMD, the following occurred: Received error message "unknown/inappropiate name or symbol" while evaluating "w[0]" from constrain expression "w[0]


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

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
 
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>
Constraint expressions use K0, K1, etc., to represent the fit coefficients, not w[0], etc. So change T_constraints[0]= {"w[0]<0.99999","w[0]>0.00001"} to T_constraints[0]= {"K0<0.99999","K0>0.00001"}

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com