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
 Origin Forum
 non-linear fitting function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

yu1

2 Posts

Posted - 09/19/2000 :  3:11:00 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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.

Laurie

USA
404 Posts

Posted - 09/26/2000 :  3:14:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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).]

Go to Top of Page

Laurie

USA
404 Posts

Posted - 09/27/2000 :  2:19:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Go to Top of Page

yu1

2 Posts

Posted - 09/27/2000 :  3:21:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

Laurie

USA
404 Posts

Posted - 09/28/2000 :  8:51:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Go to Top of Page

doncev

Germany
10 Posts

Posted - 02/24/2004 :  08:16:39 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 02/24/2004 :  11:37:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
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