Origin Ver. and Service Release (Select Help-->About Origin):9.1/sr3/B75
Operating System:Win 7
I'm trying (unsuccessfully) to convert an algorithm I have written in labscript to OriginC- the processing time is excessive in Labscript (15 minutes per fit). Basically, it uses the newton method to fit a trinomial based on collected data (competitive displacement).
The labscript algorithm:
a=Kg*Kc;
b=Kg+Kc+Kg*Kc*G0-Kg*Kc*H0+Kg*Kc*Cs;
c=Kg*G0-Kg*H0-Kc*H0+Kc*Cs+1;
d=-H0;
for (H=H0, step=1; abs(step)>1E-15; H=H-step){
step=(a*H*H*H+b*H*H+c*H+d)/(3*a*H*H+2*b*H+c);};
f=Ig+((Igh-Ig)*(Kg*H)/(1+Kg*H))
And my initial attempt in OriginC:
void _nlsfOriginCCompetitiveBinding(
// Fit Parameter(s):
double Kc, double Ig, double Igh, double Kg, double H0, double G0, double H,
// Independent Variable(s):
double Cs,
// Dependent Variable(s):
double& f)
{
// Beginning of editable part
double a; a=Kg*Kc;
double b; b=Kg+Kc+Kg*Kc*G0-Kg*Kc*H0+Kg*Kc*Cs;
double c; c=Kg*G0-Kg*H0-Kc*H0+Kc*Cs+1;
double d; d=-H0;
double step; for (H=H0, step=1; abs(step)>1E-15; H=H-step){
step=(a*H*H*H+b*H*H+c*H+d)/(3*a*H*H+2*b*H+c);};
f=Ig+((Igh-Ig)*(Kg*H)/(1+Kg*H))
// End of editable part
}
I don't get compile errors, but the fit is not correct- any suggestions as to where I'm going wrong?