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
 Fitting summation 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

hobkim

7 Posts

Posted - 06/19/2021 :  02:12:00 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I would like to ask how to build the fitting function below that includes summation.



I was trying to fit this in NLfit using the Function Type of Equations. So, I put x in the independent variables, and y in the dependent variables and, A, B, and C in the Parameters. But I have no idea of how to deal with the latter term having the summation function.

Perhaps, it should be done using Origin C or a different function type? Actually, I checked some past postings in this forum to get some hints but unfortunately I was not able to understand how it goes.

Can you please help me with building this equation?

YimingChen

1685 Posts

Posted - 06/21/2021 :  08:49:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You will need to define such function with Python in Origin. See the tutorial below:
https://www.originlab.com/doc/python/tools/NLFit-and-Peak-Analyzer

James
Go to Top of Page

hobkim

7 Posts

Posted - 06/22/2021 :  1:09:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

You will need to define such function with Python in Origin. See the tutorial below:
https://www.originlab.com/doc/python/tools/NLFit-and-Peak-Analyzer

James



Thank you so much.
Please let me try this!
Go to Top of Page

hobkim

7 Posts

Posted - 06/23/2021 :  3:07:50 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

You will need to define such function with Python in Origin. See the tutorial below:
https://www.originlab.com/doc/python/tools/NLFit-and-Peak-Analyzer

James



Hi, I tried it according to your guide and I realized that this can be done using the python function. However, I was not able to find the python in the function type as you can see in this image.



Actually, I confirmed the python embedded while I was reinstalling the whole software. But still, it's not activated. Could you please give some guideline to run the python for the Fitting Function Builder?
Go to Top of Page

YimingChen

1685 Posts

Posted - 06/23/2021 :  3:10:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You will need to upgrade your Origin to 2021b to see the option to use Python. Thank you.

James
Go to Top of Page

hobkim

7 Posts

Posted - 06/23/2021 :  10:40:47 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

You will need to upgrade your Origin to 2021b to see the option to use Python. Thank you.

James



Thanks for your comment.
I upgraded Origin to 2021b and I tried the example that you first suggested.
But it does not work showing the error popup window. It does not allow the next step.



Could you please check this and comment?
Thank you for your support.
Go to Top of Page

YimingChen

1685 Posts

Posted - 06/24/2021 :  09:07:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Please change the function body to:
y = MassDiffuse(x, y0, D, L)


James
Go to Top of Page

hobkim

7 Posts

Posted - 06/24/2021 :  10:02:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much, James,
It finally works!
Now I think I can try my equation as well!
Thanks again!
Go to Top of Page

hobkim

7 Posts

Posted - 06/24/2021 :  11:33:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks to your help, I finally tried to build the equation but it was not working very well.
I think it's because there is a difference between my equation and the equation of the example (https://www.originlab.com/doc/python/tools/NLFit-and-Peak-Analyzer).

In the example equation which is x, y function, there is no x in the function but instead t. In my equation which is also x, y function, there is already x.

I guess there would be something that I have to modify perhaps the iteration part "for in". I have tried this and that, but unfortunately, it never works. Could you please have a look at the function that I built below and tell me what's wrong?

from mpmath import nsum, exp, inf
import numpy as np

def Elliot(x, A, B, C):
sm = [float((nsum(lambda ii: 1/ii**3*(x-B+C/ii**2),[0, inf]))) for x in t]
return [A*((x-B)*np.pi*exp(np.pi)*(C/(x-B))**0.5/np.sinh(np.pi*(C/x-B)**0.5)+C*4*np.pi*t)) for t in sm]

I really appreciate your help.
Go to Top of Page

YimingChen

1685 Posts

Posted - 06/24/2021 :  1:56:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Please define Python function with script below:

from mpmath import nsum, exp, inf
import numpy as np

def f(x, nn, B, C):
    return 4*np.pi/nn**3*(x-B+C/nn**2)
    
def g(x, B, C):
    return (x-B)*np.pi*exp(np.pi)*(C/(x-B))**0.5/np.sinh(np.pi*(C/(x-B))**0.5)

def Elliot(x, A, B, C):
    return [float(A*(g(t, B, C) + C*(nsum(lambda nn: f(t,nn, B, C),[1, inf])))) for t in x]




Make sure to install mpmath Python package (menu Connectivity->Python Pakcages...)

James
Go to Top of Page

hobkim

7 Posts

Posted - 06/25/2021 :  01:27:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It works! Thank you very much for your time and effort to help me!
Have a great day and All the best!
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