The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Increase fitted datapoints
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

StephanLom

Germany
2 Posts

Posted - 07/02/2009 :  05:26:19 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

StephanLom

Germany
2 Posts

Posted - 07/02/2009 :  05:48:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Solved it, thanks though :)
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000