
Fitting subrange data with constraints

TRK
Function FitSpectrum(ww,xx) : FitFunc WAVE ww variable xx SetScale/I X, 5,30 Variable w1=0,w2=0,w3=0,w4=0,w5=0,w6=0,w7=0,qq=0 Variable T1=0.24, S1=0.047, T2=0.24, S2=0.047, x1=1.908, x2=1.918, //Variable StartP, EndP //StartP=xx[5] //EndP=xx[30] w1 = exp(0.5*(S1/T1)^2-(xx-x1)/T1) w2 = erfc(0.707*(S1/T1-(xx-x1)/S1)) w3 = ww[0] w7 = ww[1] w8 = exp(-((xx-x3)/S3)^2 qq = w3*(w1*w2)+w7*w8 return qq //////////// I called this fit equation to fit mulitple spectrums that make up a 2D data (raw data) using this code <pre><code class="language-igor"> Function ProcessData(DataFolderName, DataName) String DataFolderName, DataName Variable i DFRef OldDF=GetDataFolderDFR() SetDataFolder $DataFolderName Wave Data=$DataName Duplicate /O Data $("fit_"+DataName) Make /O /N=(DimSize(Data,1)) A1, A2 Make/O/D/N=2 T_Constraints Make /FREE /D /N=2 w_coef={1,2} Make /FREE /N=(Dimsize(Data,0)) Fit SetScale X, 5,30 For (i=0;i<Dimsize(Data,1);i+=1) //Display /K=3 /W=(10*i,10*i+40, 10*i+440, 10*i+40+210) Data[][i]/TN=$(DataName+"_"+Num2str(i)) as DataName+"_"+num2str(i) T_Constraints= {A1[i] > 1e-10,A1[i] < 1.0001,A2[i] > 1e-10,A2[i] < 1.0001} FuncFit /Q FitSpectrum w_coef Data[][i]/D=Fit/C=T_Constraints //this fit function for constraint works //FuncFit /Q FitSpectrum w_coef Data[][i]/D=Fit/X=xx(5, 30)/C=T_Constraints // does not work when flag for subrange of data is added I would appreciate any thoughts or help.
The constraint wave also need to be a text wave and you have to use K0, K1, K2 etc... to describe your variables (In your case K0 is w_coef[0] and K1 is w_coef[1]). A statement such as "A1[i] > 1e-10" makes no sense since A1 is not a fit variable. Read
DisplayHelpTopic "Fitting with Constraints"
January 22, 2018 at 02:04 am - Permalink
Coming back to the subrange data, the fit does not work and I am assuming error in the line where I call Funcfit
January 22, 2018 at 09:50 am - Permalink