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
 Origin Forum
 nonlinear curve fitting with multiple equations

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
GaussianFit Posted - 03/31/2010 : 02:05:52 AM
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 8.0 SR6
Operating System: Windows XP SP2

OK, here is the trouble I'm running into: so far I've only done curve fitting with a simple user defined function, such as y=p1/(x-p2). But now I need to fit a curve using a little complicated function that is better off calculated in multiple steps. For example:

independent variable: x
dependent variables: y

There are 3 free fitting parameters: a, b, c

First I need to calculate two intermediate variables:
d1=a/7b; (this is easy)
d2=a(10+20/(6ab-5+8a*x)+a/7b; (this one has independent x)

Using d1 and d2, I need to calculate intermediate variable u:

u=b-(x/2a)*(d2-d1)+(15x/(d2+d1)*ln(d1(a+d1)/d2(a-d2));

finally, I need to calculate variable y:

y=100*c/(d2-d1)*((u*exp(-5*(d2-d1)*u^0.5)-(u+x)*exp(-5*(d2+d1)*(u+x)^0.5))

and use it to fit the data curve y(x).

What would be the simplest way of doing this? It would be nice if I could simply type a few equations in the graphic wizard, since I know nothing about Origin C and never wrote any script before. Any suggestion is appreciated.



7   L A T E S T    R E P L I E S    (Newest First)
GaussianFit Posted - 04/02/2010 : 12:55:43 PM
You are right, I forgot to paste the declaration part. Thanks for pointing it out.

quote:
Originally posted by Sam Fang

Intermediate variables such as d1, d2 and u needn't be included in the list of fitting parameters. You can declare the intermediate variables in Code Builder. In fact the above script declares them in Code Builder. The declaration of intermediate variables and expressions can all be pasted as the function body which is not grayed out and can be edited in Code Builder.

Sam
OriginLab Technical Services

Sam Fang Posted - 04/01/2010 : 10:16:07 PM
Intermediate variables such as d1, d2 and u needn't be included in the list of fitting parameters. You can declare the intermediate variables in Code Builder. In fact the above script declares them in Code Builder. The declaration of intermediate variables and expressions can all be pasted as the function body which is not grayed out and can be edited in Code Builder.
quote:
It worked like a charm! It looks like I had to include all the intermediate variables in the list of fitting parameters, so that they will be declared in the Origin C code builder (this part is grayed out so I can't edit it). To get the fitting started, I did manually set initial values for all the parameters, although those intermediate ones should be automatically calculated. But it worked for me this way.


Sam
OriginLab Technical Services
larry_lan Posted - 04/01/2010 : 02:20:43 AM
In the Parameter Settings dialog, you need to click the cell on LB or UB column, to make "<=" or "<" appears. Then you can set the value.

You can also set these values during fitting.

Larry
GaussianFit Posted - 03/31/2010 : 10:21:44 PM
It worked like a charm! It looks like I had to include all the intermediate variables in the list of fitting parameters, so that they will be declared in the Origin C code builder (this part is grayed out so I can't edit it). To get the fitting started, I did manually set initial values for all the parameters, although those intermediate ones should be automatically calculated. But it worked for me this way.

Now I've got another question: how could I set limits for certain fitting parameters, such as lower bound and upper bound? I tried to input some numbers in the parameter table, but the only place that allowed me to edit is the column of initial values and the check box to set free/fixed parameters.

quote:
Originally posted by Sam Fang

Yes. You can just paste the script in the Code Builder. Remember to click Compile button to compile the function as the tutorial does. Note that the script assumes that a/bc is a/(b*c). And you should check whether the added parentheses are what you want.
Thanks.

Sam
OriginLab Technical Services

Sam Fang Posted - 03/31/2010 : 10:10:33 PM
Yes. You can just paste the script in the Code Builder. Remember to click Compile button to compile the function as the tutorial does. Note that the script assumes that a/bc is a/(b*c). And you should check whether the added parentheses are what you want.
Thanks.

Sam
OriginLab Technical Services
GaussianFit Posted - 03/31/2010 : 12:35:34 PM
Thanks a bunch for your fast answer! Yes I made a few typos in the expressions, they were used just as examples anyway.

So from the tutorial, it looks like I should open the Origin Code Builder, and input my own Origin C code there. Is it sufficient to copy & paste the code you posted there and then it's done? I'll give it a try and report back here.
Sam Fang Posted - 03/31/2010 : 03:32:39 AM
There are several problems in your expressions.
1. d1=a/7b;
It's not clear whether it is a/(7*b) or a/7*b. The same problem occurs in d2, u.
2. Parentheses are mismatched in d2, u, y.

Currently Origin only provides Origin C for user defined fitting functions. In fact Origin C is not as difficult as you think. Here is an example.
------------------------------
	double d1, d2, u;
	d1 = a/(7*b);
	d2 = a*( 10 + 20/(6*a*b - 5 + 8*a*x) )+a/(7*b); 
	u = b - (x/(2*a))*(d2 - d1) + ( 15*x/(d2 + d1) )*ln( d1*(a + d1)/( d2*(a - d2) ) );
	y = 100*c/(d2 - d1)*( u*exp( -5*(d2 - d1)*u^0.5 ) - (u + x)*exp( -5*(d2 + d1)*(u + x)^0.5 ) );

-------------------------------
You need modify the above script according to your problem.

For more information on how to define fitting functions in Fitting Function Organizer, you can refer to the CHM (Select Help: Origin):
Tutorials> Fitting> User Defined Fitting Function using Origin C
Or the following link:
http://www.originlab.com/www/helponline/Origin/en/mergedProjects/Tutorial/Tutorial/User_Defined_Fitting_Function_using_OC.html

Sam
OriginLab Technical Services

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