ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 04 Jul 2016 18:52:55 +0200- numerical computation of roots (maple equivalent of fsolve) of a system of nonlinear equations with multiple variables parametershttps://ask.sagemath.org/question/34002/numerical-computation-of-roots-maple-equivalent-of-fsolve-of-a-system-of-nonlinear-equations-with-multiple-variables-parameters/ Hi All, the following is my code:
### Begin Code#####
#Parameters:
k0 = 0.1
kd = 0.05
k1 = 20
j1 = 0.1
km1 = 0.2
jm1 = 0.1
k2 = 0.055
j2 = 0.1
pPTEN = 0.001
dPTEN = 0.0054
k3 = 0.006
j3 = 2
k4 = 0.15
j4 = 0.1
km4 = 73
jm4 = 0.5
pMdm2 = 0.018
dMdm2 = 0.015
dMdm2s = 0.015
k5 = 0.024
j5 = 1
k6 = 10
j6 = 0.3
km6 = 0.2
jm6 = 0.1
n1 = 3
n2 = 3
PIPtot = 1
AKTtot = 1
#Variables to solve
p53 = var('p53')
AKTs = var('AKTs')
Mdm2 = var('Mdm2')
Mdm2s = var('Mdm2s')
PIP3 = var('PIP3')
PTEN = var('PTEN')
AKT = AKTtot - AKTs
PIP2 = PIPtot - PIP3
#Rate Equations
v0 = k0
v1 = (k1 * PIP3 * AKT) / (j1 + AKT)
vm1 = (km1 * AKTs) / (jm1 + AKTs)
v2 = (k2 * Mdm2s * p53) / (j2 + p53)
v3 = (k3 * ((p53)^n1))/(((j3)^n1) + ((p53)^n1))
v4 = (k4 * PIP2)/(j4 + PIP2)
vm4 = (km4 * PTEN * PIP3)/(jm4 + PIP3)
v5 = (k5 * ((p53)^n2))/(((j5)^n2) + ((p53)^n2))
v6 = (k6 * Mdm2 * AKTs)/(j6 + Mdm2)
vm6 = (km6 * Mdm2s)/(jm6 + Mdm2s)
ss_p53 = v0 - v2 - kd*p53
ss_AKTs = v1 - vm1
ss_PIP3 = v4 - vm4
ss_PTEN = pPTEN + v3 - dPTEN * PTEN
ss_Mdm2s = v6 - vm6 - dMdm2s*Mdm2s
ss_Mdm2 = pMdm2 + v5 - v6 + vm6 - dMdm2*Mdm2
#Equation to Solve
z = solve([ss_p53==0, ss_AKTs==0, ss_PIP3==0, ss_PTEN==0, ss_Mdm2s==0, ss_Mdm2==0],\ [p53, AKTs, PIP3,PTEN, Mdm2s, Mdm2])
End Code
I tried using Sage "solve" to analytically solve the system of equations. I got a "FloatingPointError: Floating point exception"
I thought of ways to get round this exception by
1) using log and exp in my math equations -- I can't work round this
2) I have no idea how to create exceptions for this since I can't access the sub-solutions while the solutions are still underway
3)Then I tried maxima.solve --> no roots could be found
Maybe, this problem can't be solved analytically, so I thought maybe I could do so numerically.
Hence my following question,
I can only find functions that tackle univariate equations. Is there a sage equivalent of maple's f-solve which numerically computes all roots of multivariate system of nonlinear equations without the need of initial conditions?
Thanks a lot! I would really appreciate this
Rgds
Samantha
Sun, 03 Jul 2016 19:02:15 +0200https://ask.sagemath.org/question/34002/numerical-computation-of-roots-maple-equivalent-of-fsolve-of-a-system-of-nonlinear-equations-with-multiple-variables-parameters/
- Answer by calc314 for <p>Hi All, the following is my code:</p>
<pre><code>### Begin Code#####
#Parameters:
k0 = 0.1
kd = 0.05
k1 = 20
j1 = 0.1
km1 = 0.2
jm1 = 0.1
k2 = 0.055
j2 = 0.1
pPTEN = 0.001
dPTEN = 0.0054
k3 = 0.006
j3 = 2
k4 = 0.15
j4 = 0.1
km4 = 73
jm4 = 0.5
pMdm2 = 0.018
dMdm2 = 0.015
dMdm2s = 0.015
k5 = 0.024
j5 = 1
k6 = 10
j6 = 0.3
km6 = 0.2
jm6 = 0.1
n1 = 3
n2 = 3
PIPtot = 1
AKTtot = 1
#Variables to solve
p53 = var('p53')
AKTs = var('AKTs')
Mdm2 = var('Mdm2')
Mdm2s = var('Mdm2s')
PIP3 = var('PIP3')
PTEN = var('PTEN')
AKT = AKTtot - AKTs
PIP2 = PIPtot - PIP3
#Rate Equations
v0 = k0
v1 = (k1 * PIP3 * AKT) / (j1 + AKT)
vm1 = (km1 * AKTs) / (jm1 + AKTs)
v2 = (k2 * Mdm2s * p53) / (j2 + p53)
v3 = (k3 * ((p53)^n1))/(((j3)^n1) + ((p53)^n1))
v4 = (k4 * PIP2)/(j4 + PIP2)
vm4 = (km4 * PTEN * PIP3)/(jm4 + PIP3)
v5 = (k5 * ((p53)^n2))/(((j5)^n2) + ((p53)^n2))
v6 = (k6 * Mdm2 * AKTs)/(j6 + Mdm2)
vm6 = (km6 * Mdm2s)/(jm6 + Mdm2s)
ss_p53 = v0 - v2 - kd*p53
ss_AKTs = v1 - vm1
ss_PIP3 = v4 - vm4
ss_PTEN = pPTEN + v3 - dPTEN * PTEN
ss_Mdm2s = v6 - vm6 - dMdm2s*Mdm2s
ss_Mdm2 = pMdm2 + v5 - v6 + vm6 - dMdm2*Mdm2
#Equation to Solve
z = solve([ss_p53==0, ss_AKTs==0, ss_PIP3==0, ss_PTEN==0, ss_Mdm2s==0, ss_Mdm2==0],\ [p53, AKTs, PIP3,PTEN, Mdm2s, Mdm2])
End Code
</code></pre>
<p>I tried using Sage "solve" to analytically solve the system of equations. I got a "FloatingPointError: Floating point exception"</p>
<p>I thought of ways to get round this exception by
1) using log and exp in my math equations -- I can't work round this
2) I have no idea how to create exceptions for this since I can't access the sub-solutions while the solutions are still underway
3)Then I tried maxima.solve --> no roots could be found</p>
<p>Maybe, this problem can't be solved analytically, so I thought maybe I could do so numerically.
Hence my following question,</p>
<p>I can only find functions that tackle univariate equations. Is there a sage equivalent of maple's f-solve which numerically computes all roots of multivariate system of nonlinear equations without the need of initial conditions?</p>
<p>Thanks a lot! I would really appreciate this</p>
<p>Rgds
Samantha</p>
https://ask.sagemath.org/question/34002/numerical-computation-of-roots-maple-equivalent-of-fsolve-of-a-system-of-nonlinear-equations-with-multiple-variables-parameters/?answer=34004#post-id-34004 I suggest using a solver from `scipy`. You can look here: http://docs.scipy.org/doc/scipy-0.17.0/reference/optimize.nonlin.html
Below is some code to try. It does not successfully solve the equations, but I have no idea what a reasonable guess would be to start the solver with. I imagine that you have some idea of a good starting guess.
import numpy as np
import scipy.optimize as spo
#Variables to solve
p53 = var('p53')
AKTs = var('AKTs')
Mdm2 = var('Mdm2')
Mdm2s = var('Mdm2s')
PIP3 = var('PIP3')
PTEN = var('PTEN')
def G(x):
p53=x[0]
AKTs=x[1]
PIP3=x[2]
PTEN=x[3]
Mdm2s=x[4]
Mdm2=x[5]
#Parameters:
k0 = 0.1
kd = 0.05
k1 = 20
j1 = 0.1
km1 = 0.2
jm1 = 0.1
k2 = 0.055
j2 = 0.1
pPTEN = 0.001
dPTEN = 0.0054
k3 = 0.006
j3 = 2
k4 = 0.15
j4 = 0.1
km4 = 73
jm4 = 0.5
pMdm2 = 0.018
dMdm2 = 0.015
dMdm2s = 0.015
k5 = 0.024
j5 = 1
k6 = 10
j6 = 0.3
km6 = 0.2
jm6 = 0.1
n1 = 3
n2 = 3
PIPtot = 1
AKTtot = 1
AKT = AKTtot - AKTs
PIP2 = PIPtot - PIP3
#Rate Equations
v0 = k0
v1 = (k1 * PIP3 * AKT) / (j1 + AKT)
vm1 = (km1 * AKTs) / (jm1 + AKTs)
v2 = (k2 * Mdm2s * p53) / (j2 + p53)
v3 = (k3 * ((p53)^n1))/(((j3)^n1) + ((p53)^n1))
v4 = (k4 * PIP2)/(j4 + PIP2)
vm4 = (km4 * PTEN * PIP3)/(jm4 + PIP3)
v5 = (k5 * ((p53)^n2))/(((j5)^n2) + ((p53)^n2))
v6 = (k6 * Mdm2 * AKTs)/(j6 + Mdm2)
vm6 = (km6 * Mdm2s)/(jm6 + Mdm2s)
ss_p53 = v0 - v2 - kd*p53
ss_AKTs = v1 - vm1
ss_PIP3 = v4 - vm4
ss_PTEN = pPTEN + v3 - dPTEN * PTEN
ss_Mdm2s = v6 - vm6 - dMdm2s*Mdm2s
ss_Mdm2 = pMdm2 + v5 - v6 + vm6 - dMdm2*Mdm2
return(np.array([ss_p53, ss_AKTs, ss_PIP3, ss_PTEN, ss_Mdm2s, ss_Mdm2]))
guess=[1,1,1,1,1,1]
spo.newton_krylov(G,guess)Mon, 04 Jul 2016 04:56:10 +0200https://ask.sagemath.org/question/34002/numerical-computation-of-roots-maple-equivalent-of-fsolve-of-a-system-of-nonlinear-equations-with-multiple-variables-parameters/?answer=34004#post-id-34004
- Comment by sam_kjm for <p>I suggest using a solver from <code>scipy</code>. You can look here: <a href="http://docs.scipy.org/doc/scipy-0.17.0/reference/optimize.nonlin.html">http://docs.scipy.org/doc/scipy-0.17....</a></p>
<p>Below is some code to try. It does not successfully solve the equations, but I have no idea what a reasonable guess would be to start the solver with. I imagine that you have some idea of a good starting guess.</p>
<pre><code>import numpy as np
import scipy.optimize as spo
#Variables to solve
p53 = var('p53')
AKTs = var('AKTs')
Mdm2 = var('Mdm2')
Mdm2s = var('Mdm2s')
PIP3 = var('PIP3')
PTEN = var('PTEN')
def G(x):
p53=x[0]
AKTs=x[1]
PIP3=x[2]
PTEN=x[3]
Mdm2s=x[4]
Mdm2=x[5]
#Parameters:
k0 = 0.1
kd = 0.05
k1 = 20
j1 = 0.1
km1 = 0.2
jm1 = 0.1
k2 = 0.055
j2 = 0.1
pPTEN = 0.001
dPTEN = 0.0054
k3 = 0.006
j3 = 2
k4 = 0.15
j4 = 0.1
km4 = 73
jm4 = 0.5
pMdm2 = 0.018
dMdm2 = 0.015
dMdm2s = 0.015
k5 = 0.024
j5 = 1
k6 = 10
j6 = 0.3
km6 = 0.2
jm6 = 0.1
n1 = 3
n2 = 3
PIPtot = 1
AKTtot = 1
AKT = AKTtot - AKTs
PIP2 = PIPtot - PIP3
#Rate Equations
v0 = k0
v1 = (k1 * PIP3 * AKT) / (j1 + AKT)
vm1 = (km1 * AKTs) / (jm1 + AKTs)
v2 = (k2 * Mdm2s * p53) / (j2 + p53)
v3 = (k3 * ((p53)^n1))/(((j3)^n1) + ((p53)^n1))
v4 = (k4 * PIP2)/(j4 + PIP2)
vm4 = (km4 * PTEN * PIP3)/(jm4 + PIP3)
v5 = (k5 * ((p53)^n2))/(((j5)^n2) + ((p53)^n2))
v6 = (k6 * Mdm2 * AKTs)/(j6 + Mdm2)
vm6 = (km6 * Mdm2s)/(jm6 + Mdm2s)
ss_p53 = v0 - v2 - kd*p53
ss_AKTs = v1 - vm1
ss_PIP3 = v4 - vm4
ss_PTEN = pPTEN + v3 - dPTEN * PTEN
ss_Mdm2s = v6 - vm6 - dMdm2s*Mdm2s
ss_Mdm2 = pMdm2 + v5 - v6 + vm6 - dMdm2*Mdm2
return(np.array([ss_p53, ss_AKTs, ss_PIP3, ss_PTEN, ss_Mdm2s, ss_Mdm2]))
guess=[1,1,1,1,1,1]
spo.newton_krylov(G,guess)
</code></pre>
https://ask.sagemath.org/question/34002/numerical-computation-of-roots-maple-equivalent-of-fsolve-of-a-system-of-nonlinear-equations-with-multiple-variables-parameters/?comment=34006#post-id-34006Hey thanks!
Is there a way to try out multiple guesses(in an array) for multiple variables? Or any function that can do away with initial guesses or set a boundary of solutions within an interval?Mon, 04 Jul 2016 05:55:39 +0200https://ask.sagemath.org/question/34002/numerical-computation-of-roots-maple-equivalent-of-fsolve-of-a-system-of-nonlinear-equations-with-multiple-variables-parameters/?comment=34006#post-id-34006
- Comment by calc314 for <p>I suggest using a solver from <code>scipy</code>. You can look here: <a href="http://docs.scipy.org/doc/scipy-0.17.0/reference/optimize.nonlin.html">http://docs.scipy.org/doc/scipy-0.17....</a></p>
<p>Below is some code to try. It does not successfully solve the equations, but I have no idea what a reasonable guess would be to start the solver with. I imagine that you have some idea of a good starting guess.</p>
<pre><code>import numpy as np
import scipy.optimize as spo
#Variables to solve
p53 = var('p53')
AKTs = var('AKTs')
Mdm2 = var('Mdm2')
Mdm2s = var('Mdm2s')
PIP3 = var('PIP3')
PTEN = var('PTEN')
def G(x):
p53=x[0]
AKTs=x[1]
PIP3=x[2]
PTEN=x[3]
Mdm2s=x[4]
Mdm2=x[5]
#Parameters:
k0 = 0.1
kd = 0.05
k1 = 20
j1 = 0.1
km1 = 0.2
jm1 = 0.1
k2 = 0.055
j2 = 0.1
pPTEN = 0.001
dPTEN = 0.0054
k3 = 0.006
j3 = 2
k4 = 0.15
j4 = 0.1
km4 = 73
jm4 = 0.5
pMdm2 = 0.018
dMdm2 = 0.015
dMdm2s = 0.015
k5 = 0.024
j5 = 1
k6 = 10
j6 = 0.3
km6 = 0.2
jm6 = 0.1
n1 = 3
n2 = 3
PIPtot = 1
AKTtot = 1
AKT = AKTtot - AKTs
PIP2 = PIPtot - PIP3
#Rate Equations
v0 = k0
v1 = (k1 * PIP3 * AKT) / (j1 + AKT)
vm1 = (km1 * AKTs) / (jm1 + AKTs)
v2 = (k2 * Mdm2s * p53) / (j2 + p53)
v3 = (k3 * ((p53)^n1))/(((j3)^n1) + ((p53)^n1))
v4 = (k4 * PIP2)/(j4 + PIP2)
vm4 = (km4 * PTEN * PIP3)/(jm4 + PIP3)
v5 = (k5 * ((p53)^n2))/(((j5)^n2) + ((p53)^n2))
v6 = (k6 * Mdm2 * AKTs)/(j6 + Mdm2)
vm6 = (km6 * Mdm2s)/(jm6 + Mdm2s)
ss_p53 = v0 - v2 - kd*p53
ss_AKTs = v1 - vm1
ss_PIP3 = v4 - vm4
ss_PTEN = pPTEN + v3 - dPTEN * PTEN
ss_Mdm2s = v6 - vm6 - dMdm2s*Mdm2s
ss_Mdm2 = pMdm2 + v5 - v6 + vm6 - dMdm2*Mdm2
return(np.array([ss_p53, ss_AKTs, ss_PIP3, ss_PTEN, ss_Mdm2s, ss_Mdm2]))
guess=[1,1,1,1,1,1]
spo.newton_krylov(G,guess)
</code></pre>
https://ask.sagemath.org/question/34002/numerical-computation-of-roots-maple-equivalent-of-fsolve-of-a-system-of-nonlinear-equations-with-multiple-variables-parameters/?comment=34023#post-id-34023I am not aware of any. You can probably use a loop to try out multiple guesses, but will need to use Python's `try...except` command to prevent errors from stopping your loop.Mon, 04 Jul 2016 18:52:55 +0200https://ask.sagemath.org/question/34002/numerical-computation-of-roots-maple-equivalent-of-fsolve-of-a-system-of-nonlinear-equations-with-multiple-variables-parameters/?comment=34023#post-id-34023