| StephanLom
 
                Germany2 Posts
 | 
                    
                      |  Posted - 07/02/2009 :  05:26:19 AM           
 |  
                      | Hello everyone, I'm fitting several datasets with a NLFit using a user definded fitting function.
 The tricky part is, that I have to build two numerical integrals, while one is the integral
 of the fitted function. Even though I use the trapezoid rule, the intergal's accuracy is
 not satisfying. I have around 2000 datapoints, but when I look at the fitted data Origin
 seems to use only 100 datapoints. Can anyone tell me how I can increase the number of
 fitted datapoints to increase the solutions accuracy?
 
 Thanks
 Stephan
 
 
 
 #include <stdio.h>
 #include <data.h>
 #include <math.h>
 #include <utilities.h>
 
 #include	<origin.H>
 #include	<ONLSF.H>
 
 //----------------------------------------------------------
 //
 void _nlsfManasOriginlabs(
 // Fit Parameter(s):
 double Ap, double Ep, double n, double b, double Ad, double Ed, double R, double Iq, double I0,
 double Htot, double cf,
 // Independent Variable(s):
 double T,
 // Dependent Variable(s):
 double& alp, double& Y, double& H)
 {
 // Beginning of editable part
 NLFitContext	*pCtxt = Project.GetNLFitContext();
 // The idea is the following: whenever parameter values change during fitting, we want to recalculate
 // the values for all three dependent variables and store them in the static vectors vY, valp, vH.
 // Then we use them to get individual values on every call.
 
 NLSFCURRINFO		stCurrInfo;
 if ( pCtxt->GetFitCurrInfo(&stCurrInfo) )
 {
 // These three vectors contain the current computed values of the dependent variables:
 static	vector	vY, valp, vH;
 
 if ( stCurrInfo.bNewParamValues )		// if parameter values changed
 {
 // Must recalculate:
 ///////////////////////////////////////
 // Get the independent data from the context:
 vector		vT;
 pCtxt->GetIndepData(&vT);
 int			nSize = vT.GetSize();
 
 ///////////////////////////////////////
 // Compute vY:
 vY.SetSize(nSize);
 vH.SetSize(nSize);
 valp.SetSize(nSize);
 // Here I assume that vY[0], vH[0], and valp[0] are 0, since ii-1 is negative if ii = 0
 vY[0] = 0.;
 vH[0] = 0.;
 valp[0] = 0.;
 for (int ii = 1; ii < nSize; ii++)
 {
 vY[ii]=0.5*(vT[ii]-vT[ii-1])*Ad*b*(exp(-Ed/(R*vT[ii]))+exp(-Ed/(R*vT[ii-1])))+vY[ii-1];
 valp[ii]=(Ap*exp(-Ep/(R*vT[ii]))*(Iq-(I0*exp(-vY[ii])))*(1-(vH[ii-1]/Htot))*(1-(vH[ii-1]/(cf*Htot)))^n)*Htot;
 vH[ii]=0.5*(vT[ii]-vT[ii-1])*(valp[ii] + valp[ii-1])*b+vH[ii-1];
 }
 //printf("vY[nSize]");
 }
 
 // Just return the already calculated quantities:
 int			index = stCurrInfo.nCurrDataIndex;
 Y = vY[index];
 alp = valp[index];
 H = vH[index];
 }
 // End of editable part
 }
 
 I'm using:
 Origin 8G SR4 v8.0951
 |  |