[GENERAL INFORMATION]
Function Name=Weibull3
Brief Description=Weibull peak function
Function Source=fgroup.Weibull3
Function Type=Built-in
Function Form=Expression
Number Of Parameters=5
Number Of Independent Variables=1
Number Of Dependent Variables=1


[FITTING PARAMETERS]
Naming Method=User-Defined
Names=y0,xc,A,w1,w2
Meanings=offset,center,amplitude,width,width
Lower Bounds=--,--,--,0.0(X,ON),0.0(X,ON)
Upper Bounds=--,--,--,--,--
Number Of Significant Digits=


[FORMULA]

S=(x-xc)/w1 + ((w2-1)/w2)^(1/w2)
y = y0+A*((w2-1)/w2)^((1-w2)/w2) * S^(w2-1) * exp(-s^w2+(w2-1)/w2)


[CONSTRAINTS]


[Parameters Initialization]
sort(x_y_curve);
//smooth(x_y_curve, 2);
y0 = yatxmax( x_y_curve );
int i1,i2,j1,j2,j3;
int uindex=x_y_curve.GetUpperIndex();
int lindex=x_y_curve.GetLowerIndex();
if ( fabs(y0-yatxmin(x_y_curve)) < 0.2*(max(y_data)-min(y_data)) )
{ // case w2 even:
	double x1 = xatymax(x_y_curve);
	double x2 = xatymin(x_y_curve);
	vector<uint> vi;
	int nn = x_data.Find(vi, (x1+x2)/2, x1>x2?x1:x2);
	IntegrationResult integ;
	vector yy;
	yy = y_data - y0;
	ocmath_integrate(x_data, yy, vi[0], vi[nn-1], &integ);
	if(x1>x2)
	{
		xc = xatymax(x_y_curve);
		A = max( y_data ) - y0;
		w1 = (x1 - x2) / 2;
	}
	else
	{
		xc = xatymin(x_y_curve);
		A = min( y_data ) - y0;
		w1 = (x2 - x1) / 2;
	}
	int iw2;
	iw2 = 2*w1 - 4*integ.Area/integ.yPeak;
	if(iw2%2)  w2=iw2+1; // make it even
	else   	   w2=iw2;
}
else
{ // case w2 odd:
	for(j1=lindex+1;j1<uindex-1;j1++)
		if(fabs(y_data[j1]-y0) < 0.001) break; // turnning point
	// compute A and xc
	for(A=0,xc=x_data[j1],j2=j1;j2<uindex;j2++)
		if( fabs(A) < fabs(y_data[j2]-y0) )  {
			xc = x_data[j2];
			A = y_data[j2] - y0;
		}
	// compute x width at y0+A/5.0
	for(i1=j1;i1<uindex-1;i1++)
		if((y_data[i1]-y0-A/5.0)*(y_data[i1+1]-y0-A/5.0)<0) break;
	
	vector<uint> vecIndex;
	if(0 < x_data.Find(vecIndex, xc) )
		i2 = vecIndex[0];
	for(;i2<uindex-1;i2++)
		if((y_data[i2]-y0+A/5.0)*(y_data[i2+1]-y0-A/5.0)<0) break;
	w1=x_data[i2]-x_data[i1]; // x width at y0+A/5.0
	w2=3.0; // just let it be 3.0
}

[CONSTANTS]


[INITIALIZATIONS]



[AFTER FITTING]



[INDEPENDENT VARIABLES]
x=


[DEPENDENT VARIABLES]
y=


[CONTROLS]
General Linear Constraints=Off
Initialization Scripts=Off
Scripts After Fitting=Off
Number Of Duplicates=0
Duplicate Offset=2
Duplicate Unit=4
Peak Center=2
Peak Width=4
Peak Amplitude=3

