Author |
Topic  |
|
hobkim
7 Posts |
Posted - 06/19/2021 : 02:12:00 AM
|
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 |
|
hobkim
7 Posts |
|
hobkim
7 Posts |
Posted - 06/23/2021 : 3:07:50 PM
|
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?
|
 |
|
YimingChen
1685 Posts |
Posted - 06/23/2021 : 3:10:48 PM
|
You will need to upgrade your Origin to 2021b to see the option to use Python. Thank you.
James |
 |
|
hobkim
7 Posts |
Posted - 06/23/2021 : 10:40:47 PM
|
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.
|
 |
|
YimingChen
1685 Posts |
Posted - 06/24/2021 : 09:07:10 AM
|
Please change the function body to:
y = MassDiffuse(x, y0, D, L)
James |
 |
|
hobkim
7 Posts |
Posted - 06/24/2021 : 10:02:12 AM
|
Thank you very much, James, It finally works! Now I think I can try my equation as well! Thanks again! |
 |
|
hobkim
7 Posts |
Posted - 06/24/2021 : 11:33:33 AM
|
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. |
 |
|
YimingChen
1685 Posts |
Posted - 06/24/2021 : 1:56:38 PM
|
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 |
 |
|
hobkim
7 Posts |
Posted - 06/25/2021 : 01:27:23 AM
|
It works! Thank you very much for your time and effort to help me! Have a great day and All the best!
|
 |
|
|
Topic  |
|
|
|