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
 Solving Implicit Equations
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

AKazak

Russia
1228 Posts

Posted - 06/26/2020 :  12:12:20 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2020b (64-bit) 9.7.5.184
Windows 7 Pro x64 SP1

Greetings!

Is there an easy way in Origin to get all X values matching to equations like this:


Thank you.


---
AK

aplotnikov

Germany
170 Posts

Posted - 06/26/2020 :  12:16:17 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It's a simple quadratic equation.
Go to Top of Page

AKazak

Russia
1228 Posts

Posted - 06/26/2020 :  12:49:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by aplotnikov

It's a simple quadratic equation.



Sure, that was an example.
Anyway, is there a tool to solve such unresolved equations?


---
AK
Go to Top of Page

AKazak

Russia
1228 Posts

Posted - 06/26/2020 :  5:06:24 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Tried applying Equation Solver app to solve the above equation, but for about 1/3 of all points, it returns non-realistic negative values of x.
Is there a way to set some conditions on the searched solution?

Thank you.


---
AK
Go to Top of Page

Sam Fang

293 Posts

Posted - 06/29/2020 :  03:53:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi AK,

You can check Initial Values for Dependent Variables in the dialog, set a positive value for initial x, and the final solution of x may be positive values.

If the problem still exists, you can tell us other parameter values, we can try it.
e.g. do you want to solve x=f(sp, sm, phi), and A, B are constants?

quote:
Originally posted by AKazak

Tried applying Equation Solver app to solve the above equation, but for about 1/3 of all points, it returns non-realistic negative values of x.
Is there a way to set some conditions on the searched solution?




Sam
OriginLab Technical Services
Go to Top of Page

AKazak

Russia
1228 Posts

Posted - 06/29/2020 :  09:32:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Sam Fang

Hi AK,

You can check Initial Values for Dependent Variables in the dialog, set a positive value for initial x, and the final solution of x may be positive values.

If the problem still exists, you can tell us other parameter values, we can try it.
e.g. do you want to solve x=f(sp, sm, phi), and A, B are constants?

quote:
Originally posted by AKazak

Tried applying Equation Solver app to solve the above equation, but for about 1/3 of all points, it returns non-realistic negative values of x.
Is there a way to set some conditions on the searched solution?



Sam
OriginLab Technical Services


Dear Sam,

Please test the following example project:
https://my.originlab.com/ftp/forum_and_kbase/Images/CM Test.opj

---
AK

Edited by - AKazak on 06/29/2020 09:32:27 AM
Go to Top of Page

EleanorGagne

USA
2 Posts

Posted - 06/29/2020 :  10:21:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I love to solve quadratic equations...
Go to Top of Page

lkb0221

China
497 Posts

Posted - 06/29/2020 :  5:13:41 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Please try the following Python which I made with the awsome 2021 beta:

If not yet, install scipy from script window

pip install scipy


Python code:

from scipy.optimize import fsolve
from math import sin
import numpy as np
import originpro as op


def equation(x, *Params):
    sp, sm, D, Phi = Params
    return Phi*(sp-x)/(x+D*(sp-x))+(1-Phi)*(sm-x)/(x+D*(sm-x))
    #sp, sm, A, B, Phi = Params
    #return Phi*(sp-X)/(sp+A*X)-(1-Phi)*(sm-X)/(sm+B*X) 
    #return [Phi*(sp-X)/(sp+A*X)-(1-Phi)*(sm-X)/(sm+B*X) for x in X]


Phis = np.linspace(0, 1, 101, endpoint=True)
Xs = []
Params = (0.1, 0.001, 0.3333, )
for Phi in Phis:
    CurrentParam = Params + (Phi, )
    Xs.append(fsolve(equation, 0, args=CurrentParam))
wks = op.new_sheet()
wks.from_list(0, Phis, lname='Phi')
wks.from_list(1, Xs, lname='Root')
graph = op.new_graph(template='line')
plot = graph[0].add_plot(wks, coly=1, colx=0, type='line')
plot.color = '#167BB2'
graph[0].yscale = 2 
graph[0].set_xlim(begin=0, end=1, step=0.1)
graph[0].set_ylim(begin=6e-4, end=0.2, step=1)
graph[0].label('legend').remove()
graph.set_int('aa', 1)


Which will produce this graph:


FYI, for anyone being interested in this new version, you can request here:
https://www.originlab.com/doc/python/originpro

Edited by - lkb0221 on 06/29/2020 5:18:32 PM
Go to Top of Page

Sam Fang

293 Posts

Posted - 06/29/2020 :  11:02:41 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi AK,

Thanks for your project file.

I defined the equation as folows:
Phi*(0.1-x)*(x+1.0/3*(0.001-x)) + (1-Phi)*(0.001-x)*(x+1.0/3*(0.1-x)) = 0


And set 1 to the initial value for x. The result looks like as below:


Can you check whether the result makes sense?

Thanks.

quote:
Originally posted by AKazak
Dear Sam,

Please test the following example project:
https://my.originlab.com/ftp/forum_and_kbase/Images/CM Test.opj

---
AK



Sam
OriginLab Technical Services
Go to Top of Page

AKazak

Russia
1228 Posts

Posted - 06/30/2020 :  05:39:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Sam Fang

Hi AK,

Thanks for your project file.

I defined the equation as folows:
Phi*(0.1-x)*(x+1.0/3*(0.001-x)) + (1-Phi)*(0.001-x)*(x+1.0/3*(0.1-x)) = 0


And set 1 to the initial value for x. The result looks like as below:
Can you check whether the result makes sense?

Thanks.

Sam
OriginLab Technical Services



The results make sense.
However, I noticed that you replaced the equation parameters with the corresonding constants:
original equation: Phi*(0.1-x)*(x+1.0/3*(0.001-x)) + (1-Phi)*(0.001-x)*(x+1.0/3*(0.1-x)) = 0
modified equation: Phi*(Cp-x)/(x+D*(Cp-x))+(1-Phi)*(Cm-x)/(x+D*(Cm-x))=0

What is the problem with using equation parameters instead of constants?


---
AK
Go to Top of Page

Sam Fang

293 Posts

Posted - 07/01/2020 :  05:40:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by AKazak

The results make sense.
However, I noticed that you replaced the equation parameters with the corresonding constants:
original equation: Phi*(0.1-x)*(x+1.0/3*(0.001-x)) + (1-Phi)*(0.001-x)*(x+1.0/3*(0.1-x)) = 0
modified equation: Phi*(Cp-x)/(x+D*(Cp-x))+(1-Phi)*(Cm-x)/(x+D*(Cm-x))=0

What is the problem with using equation parameters instead of constants?

---
AK



Hi AK,

You'd better use constants instead of constant independent variables because too many independent variables may cause the problem to be complex.

We will support to define constant parameters in a list. I added it to our bug tracking database. It will be convenient and clear for your case.

Sam
OriginLab Technical Services
Go to Top of Page

AKazak

Russia
1228 Posts

Posted - 07/01/2020 :  12:23:35 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Sam Fang

Hi AK,

You'd better use constants instead of constant independent variables because too many independent variables may cause the problem to be complex.

We will support to define constant parameters in a list. I added it to our bug tracking database. It will be convenient and clear for your case.

Sam
OriginLab Technical Services



Dear Sam,

Got it, thank you.
Can I set each independent variables to point to specific single column-label-row cell?


---
AK
Go to Top of Page

AKazak

Russia
1228 Posts

Posted - 07/01/2020 :  12:28:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by lkb0221

Please try the following Python which I made with the awsome 2021 beta:

If not yet, install scipy from script window

pip install scipy


Python code:

from scipy.optimize import fsolve
from math import sin
import numpy as np
import originpro as op


def equation(x, *Params):
    sp, sm, D, Phi = Params
    return Phi*(sp-x)/(x+D*(sp-x))+(1-Phi)*(sm-x)/(x+D*(sm-x))
    #sp, sm, A, B, Phi = Params
    #return Phi*(sp-X)/(sp+A*X)-(1-Phi)*(sm-X)/(sm+B*X) 
    #return [Phi*(sp-X)/(sp+A*X)-(1-Phi)*(sm-X)/(sm+B*X) for x in X]


Phis = np.linspace(0, 1, 101, endpoint=True)
Xs = []
Params = (0.1, 0.001, 0.3333, )
for Phi in Phis:
    CurrentParam = Params + (Phi, )
    Xs.append(fsolve(equation, 0, args=CurrentParam))
wks = op.new_sheet()
wks.from_list(0, Phis, lname='Phi')
wks.from_list(1, Xs, lname='Root')
graph = op.new_graph(template='line')
plot = graph[0].add_plot(wks, coly=1, colx=0, type='line')
plot.color = '#167BB2'
graph[0].yscale = 2 
graph[0].set_xlim(begin=0, end=1, step=0.1)
graph[0].set_ylim(begin=6e-4, end=0.2, step=1)
graph[0].label('legend').remove()
graph.set_int('aa', 1)


Which will produce this graph:


FYI, for anyone being interested in this new version, you can request here:
https://www.originlab.com/doc/python/originpro



Great suggestion!
I will try this once install Origin 2021 Beta 1.

Can I run the Python script as a before-formula script in set column value dialog?


---
AK
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 07/01/2020 :  3:13:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can call Python from LT but beta1 only allow passing some strings to your Python code but you can easily access worksheet inside your Python code to put results in some columns.

We are now working on direct LT to Python with parameter passing, so in a week or so, we can release beta2 which has both OC and LT support to call Python functions with all basic scaler and vector passing back and forth.

CP
Go to Top of Page

Sam Fang

293 Posts

Posted - 07/01/2020 :  11:29:47 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by AKazak
Dear Sam,

Got it, thank you.
Can I set each independent variables to point to specific single column-label-row cell?

---
AK



Hi AK,

Yes. We will support to define constants by column label row cell in Constants list box.

Sam
OriginLab Technical Services
Go to Top of Page

AKazak

Russia
1228 Posts

Posted - 07/02/2020 :  11:48:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Sam Fang

quote:
Originally posted by AKazak
Dear Sam,

Got it, thank you.
Can I set each independent variables to point to specific single column-label-row cell?

---
AK



Hi AK,

Yes. We will support to define constants by column label row cell in Constants list box.

Sam
OriginLab Technical Services



Glad to read this.
Is this the near future?


---
AK
Go to Top of Page

Sam Fang

293 Posts

Posted - 07/03/2020 :  03:14:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by AKazak
Glad to read this.
Is this the near future?

---
AK



Hi AK,

I added it to our bug tracking database, ID: APPS-934. I will ask our developer to fix soon.

Sam
OriginLab Technical Services
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