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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Difficulty converting Labtalk script to OriginC

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
chbattle Posted - 05/04/2015 : 1:28:06 PM
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?
1   L A T E S T    R E P L I E S    (Newest First)
chbattle Posted - 05/11/2015 : 12:10:38 PM
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.

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000