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
 non-linear fitting function

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
yu1 Posted - 09/19/2000 : 3:11:00 PM
I need to fit my histogram plot by statistical Poisson function, which contains factorial x!, I tried in different ways but never succeeded, I am wondering if it is possible to do such complicate simulation by origin 6? The function is like:
y=(P1^x/x!) e^(-P1),P1 is fitting parameter and x variable.

Thanks for your any suggestions.

6   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 02/24/2004 : 11:37:07 AM
The LabTalk script is in the Knowledge Base: Script to caluclate the factorial.

Here is the equivalent C function:
uint get_factorial(uint nValue)
{
if( !nValue ) return 1;
for(uint i=nValue; i>1; i--,nValue*=i);
return nValue;
}

As for fit vs histogram, you may need to add a normalization parameter to your fitting function:

y=P0*(P1^x/x!)*e^(-P1)

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 02/24/2004 11:43:15 AM

Edited by - Mike Buess on 02/24/2004 11:56:19 AM
doncev Posted - 02/24/2004 : 08:16:39 AM
I need to fit my histogram plot by statistical Poisson function, which contains factorial x!, I tried in different ways but never succeeded, I am wondering if it is possible to do such complicate simulation by origin 7.5? The function is like:
y=(P1^x/x!) e^(-P1),P1 is fitting parameter and x variable.

I have tried recepies you suggested on forum but for the first solution script for factorial is missing. Second solution seems to work somehow but the fit curve is well below the real histogram. Do you now what can be a reason? The solution was for Origin 6 and I am using Origin 7.5.
Thanks for your any suggestions.

Regards
Laurie Posted - 09/28/2000 : 8:51:00 PM
Yes, you can do the same with a function graph. The gammaln() and exp() functions are listed in the drop-down list. Replace P1 with the constant value.

Any other questions, let me know.

-Laurie

yu1 Posted - 09/27/2000 : 3:21:00 PM
Thanks a lot.
I have one more questions. Can I do the same to "add function graph"? I find there are aslo a lot of built-in functions in the check box, but if I need to define my own function, can I use the same script as in "curve fit"? Have a nice day.
Laurie Posted - 09/27/2000 : 2:19:00 PM
I just learned of another way you can define your user-defined function; using the gamma function, which is already built in, instead of the factorial. Actually the gammaln function is built-in, but you can get gamma(x) by using exp(gammaln(x)).

Origin's built-in function list includes a function called gammaln(x). This function represents the natural log of gamma(x). The reason why Origin provides only the natural log of gamma has to do with computational limitations. In other words, in computing gamma functions, one can quickly run off into very large numbers. To avoid this, Origin internally computes ln(gamma(x)) rather than gamma(x). (Note that this is the same reason that we don't provide a built-in factorial function in the first place...factorials also blow up very easily.)

So, using the gammaln() function, your user-defined function would be as follows:


y=(P1^x/exp(gammaln(x+1)))*exp(-P1)


The Form can now be set to equation. (Note that you don't need the Y-Script Form anymore.)

Any questions, please let me know. I'd also be happy to hear when you get it working.

Laurie Shea
Technical Support

Laurie Posted - 09/26/2000 : 3:14:00 PM
At this time, Origin does not have a built-in factorial function. We do plan on adding this for a later version.

However, you can write a script to calculate the factorial. The script can be found in the Knowledge database, http://www.originlab.com/www/tech/resultstech.asp?ItemID=241&VersionID=All&TitleID=Script+to+calculate+the+factorials+< !--+LabTalk+math+dataset+-->&CatID=Worksheet+Windows+/+Datas ets&TypeID=Script">Script to calculate the factorials.

With the ability to write a script you can then define a user-defined fitting function of Form, Y-Script. To do this, please follow these steps:

1. Open the NLSF, Analysis:Nonlinear Curve Fit. (You should be running in the Advanced Mode. You know that you are in the Advanced Mode if you see the Basic Mode button.)
2. Select Function:New.
3. In the Form drop-down list, select Y-Script.
4. Enter in your Definition as the following:

num=x;
res=num;
if(num > 1)
for(res=num;num>1;num-=1,res=res*num);
y=(p1^x/res)*exp(-p1);

5. Continue as you normally would when fitting.

Laurie Shea
Technical Support

[This message has been edited by Laurie (edited 09-26-2000).]


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