The Origin C function below is a crude but effective way to fit multiple datasets individually without plotting them first. The active window must be a worksheet in which the first column is X and the rest are Y. It fits each Y column separately and outputs the parameters and errors to separate rows in a new worksheet. (As always, the quality of each fit depends on how well its automatic parameter initialization works. That, in turn, depends mostly on the signal-to-noise ratio of your data.) A graph window is created in the process (I don't know how to suppress that yet) but should be removed automatically at the end. I will probably clean up this function and add it to the MultiFit functions on the File Exchange.void MultiFit()
{
using nlsf = LabTalk.NLSF;
string sMsg;
if( nlsf.isBadFunc )
{
sMsg.Format("%s: No such function found!",nlsf.func$);
MessageBox( GetWindow(), sMsg, "Attention!", MB_OK | MB_ICONHAND );
return;
}
string sFunc = nlsf.func$;
nlsf.init();
Worksheet ws = Project.ActiveLayer();
if( !ws )
{
sMsg = "A worksheet window must be active.";
MessageBox( GetWindow(), sMsg, "Attention!", MB_OK | MB_ICONHAND );
return;
}
string sName = Project.Pages().GetName();
int i,j,nDat = ws.Columns.Count()-1;
if( !nDat )
{
sMsg ="Active worksheet has no data.";
MessageBox( GetWindow(), sMsg, "Attention!", MB_OK | MB_ICONHAND );
return;
}
nlsf.numfitsets = 1;
nlsf.msgprompt = 0;
int nPar = nlsf.npara;
WorksheetPage wpg;
wpg.Create("Origin.otw");
wpg.Label = sFunc;
LabTalk.page.title = 3;
string wName = wpg.GetName();
Worksheet wks(wName);
wks.Columns(0).SetType(OKDATAOBJ_DESIGNATION_NONE);
wks.Columns(0).SetName("Dataset");
wks.Columns(0).SetWidth(12);
wks.Columns(1).SetName(nlsf.n$(1)$);
wks.AddCol("err1");
wks.Columns(2).SetType(OKDATAOBJ_DESIGNATION_ERROR);
for(i=1;i<nPar;i++)
{
wks.AddCol(nlsf.n$(i+1)$);
sMsg.Format("err%d",i+1);
wks.AddCol(sMsg);
wks.Columns(2*i+2).SetType(OKDATAOBJ_DESIGNATION_ERROR);
}
wks.AddCol("chisqr");
LT_execute("win -a " + sName);
for(i=0;i<nDat;i++)
{
nlsf.fitdata$ = sName + "_" + ws.Columns(i+1).GetName();
nlsf.execute("paranint");
nlsf.iterate(100);
wks.SetCell(i,0,nlsf.fitdata$);
for(j=0;j<nPar;j++)
{
wks.SetCell(i,2*j+1,nlsf.p$(1+j));
wks.SetCell(i,2*j+2,nlsf.e$(1+j));
}
wks.SetCell(i,2*nPar+1,nlsf.chiSqr);
}
LT_execute("if(exist(%H)==3) win -c %H;");
LT_execute("win -a " + wName);
}
Mike Buess
Origin WebRing Member