Author |
Topic  |
|
AKazak
Russia
1205 Posts |
Posted - 07/01/2022 : 07:53:00 AM
|
OriginPro 2022b (64-bit) SR1 9.9.5.167 Windows 7 Pro SP1 x64
Greetings!
I have the following data structure:

What is the easiest way to fill columns L, M and Y with non-linear fit parameters for the following relationship?

Can I accomplish this using a formula?
Thank you.
--- Andrey |
|
YimingChen
1664 Posts |
Posted - 07/01/2022 : 10:15:09 AM
|
You can set column values with Python function. See the example below:

import originpro as op
import numpy as np
from scipy.optimize import curve_fit
wks = op.find_sheet()
def func(x, a, b, c):
return a + (1 - a) * (b/x)**(1/c)
def fit(i, help):
'''f:i'''
x = np.linspace(1, 5, 6)
y = wks.to_list2(i,i,0,5)
popt, pcov = curve_fit(func, x, np.transpose(y)[0])
return popt[0]
|
Edited by - YimingChen on 07/01/2022 10:16:16 AM |
 |
|
AKazak
Russia
1205 Posts |
Posted - 07/01/2022 : 11:40:14 AM
|
quote: Originally posted by YimingChen
You can set column values with Python function. See the example below:
Haven't got the method. Can you share a sample project, please?
--- Andrey |
 |
|
YimingChen
1664 Posts |
|
AKazak
Russia
1205 Posts |
Posted - 07/01/2022 : 11:48:40 AM
|
quote: Originally posted by YimingChen
import originpro as op
import numpy as np
from scipy.optimize import curve_fit
wks = op.find_sheet()
def func(x, a, b, c):
return a + (1 - a) * (b/x)**(1/c)
def fit(i, help):
'''f:i'''
x = np.linspace(1, 5, 6)
y = wks.to_list2(i,i,0,5)
popt, pcov = curve_fit(func, x, np.transpose(y)[0])
return popt[0]
Few questions on the code. 1) Is help parameter of fit function redundant and can be removed?
--- Andrey |
 |
|
AKazak
Russia
1205 Posts |
|
aplotnikov
Germany
169 Posts |
Posted - 07/01/2022 : 12:14:28 PM
|
quote: Originally posted by YimingChen
You can set column values with Python function
from scipy.optimize import curve_fit
It seems to be a very promising approach: to use Python libraries instead of Origin "native" features. It gives some users (like me) something to think about... |
 |
|
YimingChen
1664 Posts |
Posted - 07/01/2022 : 12:30:22 PM
|
I don't find a way to do so with Labtalk. Looks to me the input of nlbegin has to be columns.
James
quote: Originally posted by AKazak
quote: Originally posted by YimingChen
https://my.originlab.com/ftp/forum_and_kbase/Images/fitRowWise.opju James
Dear James,
OK, now I see how it works. Can I do the same using the built-in Origin's NLF engine via LT and column formula?
--- Andrey
|
 |
|
AKazak
Russia
1205 Posts |
Posted - 07/01/2022 : 12:34:49 PM
|
quote: Originally posted by YimingChen
import originpro as op
import numpy as np
from scipy.optimize import curve_fit
wks = op.find_sheet()
def func(x, a, b, c):
return a + (1 - a) * (b/x)**(1/c)
def fit(i, help):
'''f:i'''
x = np.linspace(1, 5, 6)
y = wks.to_list2(i,i,0,5)
popt, pcov = curve_fit(func, x, np.transpose(y)[0])
return popt[0]
Few questions on the code. 1) Is help parameter of fit function redundant and can be removed?
--- Andrey |
Edited by - AKazak on 07/01/2022 12:42:06 PM |
 |
|
AKazak
Russia
1205 Posts |
Posted - 07/01/2022 : 12:43:35 PM
|
quote: Originally posted by YimingChen
I don't find a way to do so with Labtalk. Looks to me the input of nlbegin has to be columns.
James
nlbegin is a good option, but it does not output the fitting parameters to a worksheet, but to report sheet only. So I will continue using Python approach.
--- Andrey |
 |
|
YimingChen
1664 Posts |
Posted - 07/01/2022 : 1:43:07 PM
|
Yes, you can remove help parameter (the input column). It is of not much use in this case as the input columns are not passed by the function arguments.
James
quote: Originally posted by AKazak
quote: Originally posted by YimingChen
import originpro as op
import numpy as np
from scipy.optimize import curve_fit
wks = op.find_sheet()
def func(x, a, b, c):
return a + (1 - a) * (b/x)**(1/c)
def fit(i, help):
'''f:i'''
x = np.linspace(1, 5, 6)
y = wks.to_list2(i,i,0,5)
popt, pcov = curve_fit(func, x, np.transpose(y)[0])
return popt[0]
Few questions on the code. 1) Is help parameter of fit function redundant and can be removed?
--- Andrey
--- Andrey
|
 |
|
AKazak
Russia
1205 Posts |
Posted - 07/01/2022 : 2:43:14 PM
|
quote: Originally posted by YimingChen
Yes, you can remove help parameter (the input column). It is of not much use in this case as the input columns are not passed by the function arguments.
James
How do I pass the input columns by the function arguments to make the function much more universal?
--- Andrey |
 |
|
YimingChen
1664 Posts |
Posted - 07/01/2022 : 3:29:53 PM
|
It is not possible in this case as the input columns can vary. So I have to use wks.to_list2() Python function to extract data from each worksheet row.
James
|
 |
|
AKazak
Russia
1205 Posts |
Posted - 07/02/2022 : 01:21:14 AM
|
quote: Originally posted by YimingChen
It is not possible in this case as the input columns can vary. So I have to use wks.to_list2() Python function to extract data from each worksheet row.
James
Dear James,
OK, got it.
Another question on Python. I noticed that column formulas for columns L, M and Y are different in parts of Python scripts since each columns return its own component of popt vector. Does this mean that for each row fit(i, help) function is being called three times? If this is a case, then it seems like wasting the resources. Is this possible to fill columns L, M and Y with a single run of fit(i, help) function per each row?
--- Andrey |
 |
|
YimingChen
1664 Posts |
|
AKazak
Russia
1205 Posts |
Posted - 07/05/2022 : 10:23:51 AM
|
quote: Originally posted by YimingChen
Yes, you are right. the fitting function is called 3 times. Please see the updated project file. The fitted values are output in one run.
https://my.originlab.com/ftp/forum_and_kbase/Images/fitRowWise1.opju
James
Dear James,
What is the purpose of passing the col(a) to the function:
py.fit(col(A))
For me it seems that py.fit was designed in such a way that it does not require any inputs, doesn't it?
How do I modify py.fit to depend on the source data columns A:F?
--- Andrey |
Edited by - AKazak on 07/05/2022 10:24:16 AM |
 |
|
YimingChen
1664 Posts |
|
|
Topic  |
|