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 for Programming
 Forum for Origin C
 Difficulty converting Labtalk script to OriginC
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

chbattle

USA
5 Posts

Posted - 05/04/2015 :  1:28:06 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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?

chbattle

USA
5 Posts

Posted - 05/11/2015 :  12:10:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The initialization parameters aren't the problem, as I mentioned I can fit it fine via the give script written in LabTalk. All of the parameters are given set initial values and bounds based on the data to be fit, and I'm using the same initial parameters for both the Labtalk & OriginC functions.

With the OriginC fit, even after 400 iterations the curve never changes, which makes me think something is wrong with the for loop portion of the code.

Edited by - chbattle on 05/11/2015 12:12:06 PM
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