Origin Version (Select Help-->About Origin 7.5 PRO):
Operating System:XP
Hi, Mike
I want to fit a large data set at regular intervals by using 'for' loop. For example: Data range: 1,2,3,4,5,6 ... ... 120000. Fitting data set at 20 interval, Fit1: data[1-20], Fit2:data[21-40], Fit3:data[41-60]... ...
But when fitting, it run very long time and can't finish. The fitting function is very simple, so I think it's someting wrong. Then I break program by using 'ESC' key.it produce error:
*****Origin C Function Runtime Error, general operation failur*****. The error position point to the fitting function. The function is definied in Advanced Fitting Tool menu, it's no problem. This case happened even if I use other user definied function. I doubt that when I recall NLSF operation in the OC code, the fitting function can not get valid data. Can you give me some advices. Sorry for troubling you these days, thanks a lot.
The following is my function,it's definied by Advanced Fitting Tool menu.
void _nlsfWeightFitting3(
// Fit Parameter(s):
double w1, double w2, double w3,
// Independent Variable(s):
double fr1, double fg1, double fb1, double fr2, double fg2, double fb2, double fr3,
double fg3, double fb3, double Ir, double Ig, double Ib,
// Dependent Variable(s):
double& Rm, double& Gm, double& Bm)
{ <-----------*****I clicked the error info,then it point to here.*****
// Beginning of editable part
Rm=(fr1*w1 + fr2*w2 + fr3*w3)*Ir;
Gm=(fg1*w1 + fg2*w2 + fg3*w3)*Ig;
Bm=(fb1*w1 + fb2*w2 + fb3*w3)*Ib;
// End of editable part
}
The following is my OC code for fitting.
void WeightFitting3(int interval)
{
//Define Data Type.
string str;
int lsi, lsj;
int length1,length2;
//Define Process.
// Declare worksheet, data curve and error dataset and check validity
Worksheet wks = Project.ActiveLayer();
wks.GetRange(length1,length2);
//Get initial weight.
Dataset weight1(wks, 12);
Dataset weight2(wks, 13);
Dataset weight3(wks, 14);
//NLSF.
using NLSF = LabTalk.NLSF;
NLSF.begin();
NLSF.cleanUpFitData();
NLSF.msgPrompt=0;
NLSF.Output(0);
NLSF.Func$ = "WeightFitting3";
NLSF.x1$ = wks.Columns(18).GetDatasetName();
NLSF.x2$ = wks.Columns(19).GetDatasetName();
NLSF.x3$ = wks.Columns(20).GetDatasetName();
NLSF.x4$ = wks.Columns(21).GetDatasetName();
NLSF.x5$ = wks.Columns(22).GetDatasetName();
NLSF.x6$ = wks.Columns(23).GetDatasetName();
NLSF.x7$ = wks.Columns(24).GetDatasetName();
NLSF.x8$ = wks.Columns(25).GetDatasetName();
NLSF.x9$ = wks.Columns(26).GetDatasetName();
NLSF.x10$ = wks.Columns(15).GetDatasetName();
NLSF.x11$ = wks.Columns(16).GetDatasetName();
NLSF.x12$ = wks.Columns(17).GetDatasetName();
NLSF.y1$ = wks.Columns(0).GetDatasetName();
NLSF.y2$ = wks.Columns(1).GetDatasetName();
NLSF.y3$ = wks.Columns(2).GetDatasetName();
//Define constriant.
NLSF.constr$ = "0<w1<1";
NLSF.constr$ = "0<w2<1";
NLSF.constr$ = "0<w3<1";
NLSF.constr$ = "w1+w2+w3=1";
NLSF.constraints = 1;
NLSF.Wtype = 0;
NLSF.keepParam = 1;
for(lsi=0; lsi<(length2-length1+1)/interval; lsi++)
{
printf("------%d------\n",lsi);
//Initial Params.
NLSF.p1=weight1[interval*lsi];
NLSF.p2=weight2[interval*lsi];
NLSF.p3=weight3[interval*lsi];
NLSF.v1=1;
NLSF.v2=1;
NLSF.v3=1;
NLSF.dataBegin = lsi*interval;
NLSF.dataEnd = lsi*interval+interval-1;
//fitting
NLSF.Iterate(10);
NLSF.Iterate(10);
//record fitting result
for(lsj=0; lsj<interval; lsj++)
{
weight1[lsj+lsi*interval]=NLSF.p1;
weight2[lsj+lsi*interval]=NLSF.p2;
weight3[lsj+lsi*interval]=NLSF.p3;
}//lsj
}//lsi
NLSF.End(13)
}
=================================================================
Zhou Zeng, Shang Hai Jiao Tong University, China