You can use general linear constraints to effectively share a parameter between two datasets when fitting them simultaneously. For instance, try the following:
1. Import GaussFit.DAT from the Origin7\Samples\Data folder. 2. Plot columns B and D. Note their peak centers are nearly identical. 3. Open the Nonlinear Curve Fitter and select the Gauss function. 4. Select Options:Control in the fitter. 5. Enable the Enabled check box for General Linear Constraints. 6. Select Function:Save in the fitter to save the function. 7. Close the fitter and activate the graph. 8. Execute the following script in the Script window.
nlsf.init(); // initialize fitter to prep it for fitting session nlsf.func$="gauss"; // set fitting function nlsf.numFitSets=2; // define two datasets to be fitted nlsf.y1$="gaussfit_b"; // set 1st dataset to be fitted nlsf.y2$="gaussfit_d"; // set 2nd dataset to be fitted nlsf.execute(ParaInit); // execute parameter initialization routine (new to 7.0) nlsf.constr$=""; // clear constraints if any were there before nlsf.constr$="xc=xc_2;"; // set constraints nlsf.iterateEX(1000); // iterate 1000 times as if clicking Iterate button in fitter (new to 7.0) nlsf.end(); // end fitting session and output results to plot, results log, and nlsf worksheet
Note: The constraints could be "built" by checking the number numFitSets property. For instance:
%Z="xc"; // initialize constraint statement loop(ii,2,nlsf.numFitSets) { %Z=%Z=xc_$(ii); // build constraint statement } %Z="%Z;"; // add semi-colon to %Z
You would then assign %Z to nlsf.constr$ instead of manually entering the constraint. Of course, numFitSets can be set using a variable and that same variable could then be used in the loop instead of numFitSets. In doing this you could free yourself from hard coding the number of datasets you can fit at one time. | |
Hope this helps...
- rtoomey
P.S. I must apologize for not coming to you with this solution way back in February of 2001! I see you asked the same question then. Just to let you know, I added your name to a suggestion way back then to allow for an easier way to share parameters through script. I'll update the item's priority to see if we can get someone working on this soon. |