Origin Ver. and Service Release (Select Help-->About Origin): Origin 9.1
Operating System: windows vista
Hello,
I wrote a code to fit some data points. The fitting function is the convolution of function F = A + B * theta(C-x)*(C-x)^0.5 and a Gaussian function, where theta is a step function. The code and some test data points are list below.
Basically, the code can be run. But the parameter D which is the Gaussian width doesn't change. No matter what initial value I used for D, it will stay the same during the fitting and the output result is not good.
The output of the fitting has very large interval which is the same as that of the data points. How can I make it smaller and more smooth? Thanks in advance.
#pragma numlittype(push, TRUE)
#pragma warning(error : 15618)
#include <origin.h>
#include <ONLSF.H>
#include <fft_utils.h>
//----------------------------------------------------------
//
void _nlsfmeanfield_squareroot(
// Fit Parameter(s):
double A, double B, double C, double D,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
// Beginning of editable part
// if(x<C) {
// y = A+B*(C-x)^0.5
// } else {
// y = A;
// }
Worksheet wks = Project.ActiveLayer();
NLFitContext *pCtxt = Project.GetNLFitContext();
if(pCtxt)
{
int i;
// Vector for the output signal in each iteration.
static vector vF;
// If parameters were updated, we will recalculate the convolution result.
BOOL bIsNewParamValues = pCtxt->IsNewParamValues();
if ( bIsNewParamValues )
{
// Read sampling data from worksheet.
Dataset dsSampling(wks, 0);
vector vSample,vG;
vSample = dsSampling;
int nSize = dsSampling.GetSize();
vSample.SetSize(nSize);
vF.SetSize(nSize);
vG.SetSize(nSize);
for(i=0;i<=nSize;i++)
{
if(vSample[i] < C)
{
vF[i]= B * (C-vSample[i])^0.5;
}else{
vF[i]=0;
}
vG[i]=exp(-(vSample[i]-C)^2/(2*D^2))/(0.39894*D);
}
//vG=exp(-(vSample-C)^2/(2*D^2))/(0.39894*D);
int iRet = fft_fft_convolution(nSize, vF, vG);
}
NLSFCURRINFO stCurrInfo;
pCtxt->GetFitCurrInfo(&stCurrInfo);
// Get the data index for the iteration
int nCurrentIndex = stCurrInfo.nCurrDataIndex;
// Get the evaluated y value
y = vF[nCurrentIndex]+A;
// For compile the function, since we haven't use x here.
x;
// }}
}
// End of editable part
}
Test data:
15 177
50 172.3094
100 163.41035
150 151.29372
180 140.50654
200 126.92814
210 120
220 120
230 120
240 120
250 120
260 120
270 120
280 120
300 120
Best regards,
Peng