[GENERAL INFORMATION]
Function Name=BiDoseResp
Brief Description=Biphasic Dose Response Function
Function Source=fgroup.BiDoseResp
Function Type=Built-in
Function Form=Equations
Number Of Parameters=7
Number Of Independent Variables=1
Number Of Dependent Variables=1
Analytical Derivatives for User-Defined=Off


[FITTING PARAMETERS]
Naming Method=User-Defined
Names=A1, A2, LOGx01, LOGx02, h1, h2, p
Meanings=Bottom, Top, 1st EC50, 2nd EC50, slope1, slope2, proportion
Initial Values=--(V)
Lower Bounds=--(X,OFF)
Upper Bounds=--(X,OFF)
Number Of Significant Digits=


[FORMULA]
double span = A2 - A1;
double Section1 = span*p/(1+pow(10,(LOGx01-x)*h1));
double Section2 = span* (1-p)/(1+pow(10,(LOGx02-x)*h2));
y=A1 + Section1 +Section2;


[CONSTRAINTS]
/*Enter general linear constraints here*/


[CONSTANTS]


[Parameters Initialization]
sort(x_y_curve);
A1 = min( y_data );
A2 = max( y_data );
int n = y_data.GetSize()/2;
vector vX, vY;
vX.SetSize(n);
vY.SetSize(n);
for(int i = 0; i < n; i++)
{
	vX[i] = x_data[i];
	vY[i] = y_data[i];
}
Curve crv1( vX, vY );
LOGx01 = xaty50( crv1 );
for(i = n; i < 2*n; i++)
{
	vX[i-n] = x_data[i];
	vY[i-n] = y_data[i];
}
Curve crv2( vX, vY );
LOGx02 = xaty50( crv2 );
double xmin, xmax;
x_data.GetMinMax(xmin, xmax);
double range = xmax - xmin;
if ( yatxmax(x_y_curve) - yatxmin(x_y_curve) > 0)
	h1 = 5.0 / range;
else
	h1 = -5.0 / range;
h2 = h1;
p = 0.5;


[INITIALIZATIONS]
/*Code to be executed before fitting, a good place for complicated initialization.*/


[AFTER FITTING]
/*Code to be executed after fitting, a good place for generating results.*/


[ON PARAM CHANGE]
/*Code to be executed when parameters change.*/


[INDEPENDENT VARIABLES]
x=


[DEPENDENT VARIABLES]
y=


[CONTROLS]
General Linear Constraints=Off
Initialization Scripts=Off
Scripts After Fitting=Off
Number Of Duplicates=N/A
Duplicate Offset=N/A
Duplicate Unit=N/A
Generate Curves After Fitting=Yes
Curve Point Spacing=Uniform on X-Axis Scale
Generate Peaks After Fitting=Yes
Generate Peaks During Fitting=Yes
Generate Peaks with Baseline=Yes
Paste Parameters to Plot After Fitting=Yes
Paste Parameters to Notes Window After Fitting=Yes
Generate Residuals After Fitting=No
Keep Parameters=No
Enable Parameters Initialization=0
Compile On Param Change Script=1


[COMPILE FUNCTION]
Compile=1
Compile Parameters Initialization=1
On Param Change Scripts Enabled=0


[ORIGIN C FUNCTION HEADER]
#pragma warning(error : 15618)
#include <origin.h>

// Add your special include files here.
// For example, if you want to fit with functions from the NAG library, 
// add the header file for the NAG functions here.

// Add code here for other Origin C functions that you want to define in this file,
// and access in your fitting function.

// You can access C functions defined in other files, if those files are loaded and compiled 
// in your workspace, and the functions have been prototyped in a header file that you have
// included above. 

// You can access NLSF object methods and properties directly in your function code.

// You should follow C-language syntax in defining your function. 
// For instance, if your parameter name is P1, you cannot use p1 in your function code. 
// When using fractions, remember that integer division such as 1/2 is equal to 0, and not 0.5
// Use 0.5 or 1/2.0 to get the correct value.

// For more information and examples, please refer to the "User-Defined Fitting Function" 
// section of the Origin Help file.


[ORIGIN C PARAMETER INITIALIZATION HEADER]
#include <origin.h>

// Add your special include files here.
// For example, if you want to use functions from the NAG library, 
// add the header file for the NAG functions here.

// Add code here for other Origin C functions that you want to define in this file,
// and access in your parameter initialization.

// You can access C functions defined in other files, if those files are loaded and compiled 
// in your workspace, and the functions have been prototyped in a header file that you have 
// included above. 
	
// You can access NLSF object methods and properties directly in your function code.
// You should follow C-language syntax in defining your function. 
// For instance, if your parameter name is P1, you cannot use p1 in your function code. 
// When using fractions, remember that integer division such as 1/2 is equal to 0, and not 0.5
// Use 0.5 or 1/2.0 to get the correct value.

// For more information and examples, please refer to the "User-Defined Fitting Function" 
// section of the Origin Help file.


