vpasolve to find all real roots for multiple nonlinear equations and multiple variables

16 messages
Open this post in threaded view
|

vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 Hi all I would appreciate any help in this thanks! Im 2 months old to coding! Before I go on to my codes, my main aim is to find all real roots for 2 nonlinear equations(ss_prot1 and ss_prot2 which are steady-state rate equations(==0) of 2 different proteins ) that contain 2 variables( prot1 and prot2s). I am currently using the "symbolic" package 2.3 for octave source forge ## Constant parameters k0 = 0.1; #uM/min kd = 0.05; #/min k1 = 0.6; #uM/min j1 = 0.1; #uM km1 = 0.2; #uM/min jm1 = 0.1; #uM k2 = 0.4; #/min j2 = 0.1;#uM km3 = 7.05;# /min jm3 = 2; #uM ## setting the variables prot1 and prot2s total_prot2 = 2; # total protein2 in the cell syms prot1 prot2s positive; #prot2s = activated protein2 prot2 = total_prot2 - prot2s # prot2 = unactivated protein2 ## setting the rate expressions (degradation rate, production rate etc) v0 = k0; v1 = vpa((k1 * prot2) / (j1 + prot2));       vm1 = vpa((km1 * prot2s) / (jm1 + prot2s));         v2 = vpa((k2 * prot1 * prot2s) / (j2 + prot2s));         vm3 = vpa((km3 * prot1 * prot2s) / (jm3 + prot2s)); ## 2 steady state equations to be solved by vpasolve etc... ss_prot1 = v0 - v2 - kd*prot1 == 0; ss_prot2 = v1 - vm1 - vm3 == 0; equations = [ss_prot1, ss_prot2]; variables = [prot1, prot2]; ## vpasolve! [sol_prot1 sol_prot2] = vpasolve(equations, variables) Resuts: Python exception: TypeError: bad operand type for abs(): 'MutableDenseMatrix'     occurred at line 20 of the Python code block _______________________________________________________________ Does anyone know what this means? Thanks for your time!
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 On Mon, May 30, 2016 at 10:38 AM, sam kjm wrote:Hi all I would appreciate any help in this thanks! Im 2 months old to coding! Before I go on to my codes, my main aim is to find all real roots for 2 nonlinear equations(ss_prot1 and ss_prot2 which are steady-state rate equations(==0) of 2 different proteins ) that contain 2 variables( prot1 and prot2s). I am currently using the "symbolic" package 2.3 for octave source forge ## Constant parameters k0 = 0.1; #uM/min kd = 0.05; #/min k1 = 0.6; #uM/min j1 = 0.1; #uM km1 = 0.2; #uM/min jm1 = 0.1; #uM k2 = 0.4; #/min j2 = 0.1;#uM km3 = 7.05;# /min jm3 = 2; #uM ## setting the variables prot1 and prot2s total_prot2 = 2; # total protein2 in the cell syms prot1 prot2s positive; #prot2s = activated protein2 prot2 = total_prot2 - prot2s # prot2 = unactivated protein2 ## setting the rate expressions (degradation rate, production rate etc) v0 = k0; v1 = vpa((k1 * prot2) / (j1 + prot2)); vm1 = vpa((km1 * prot2s) / (jm1 + prot2s)); v2 = vpa((k2 * prot1 * prot2s) / (j2 + prot2s)); vm3 = vpa((km3 * prot1 * prot2s) / (jm3 + prot2s)); ## 2 steady state equations to be solved by vpasolve etc... ss_prot1 = v0 - v2 - kd*prot1 == 0; ss_prot2 = v1 - vm1 - vm3 == 0; equations = [ss_prot1, ss_prot2]; variables = [prot1, prot2]; ## vpasolve! [sol_prot1 sol_prot2] = vpasolve(equations, variables) Resuts: Python exception: TypeError: bad operand type for abs(): 'MutableDenseMatrix'     occurred at line 20 of the Python code block _______________________________________________________________ Does anyone know what this means? Thanks for your time!I dont know to full answer but I see that "variables" on line 37 is: [prot₁  -prot2s + 2]  The + 2 looks wrong to me.-- DAS _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 Thanks for pointing that out! My updated codes are as follows: ## Constant parameters k0 = 0.1; #uM/min kd = 0.05; #/min k1 = 0.6; #uM/min j1 = 0.1; #uM km1 = 0.2; #uM/min jm1 = 0.1; #uM k2 = 0.4; #/min j2 = 0.1;#uM km3 = 7.05;# /min jm3 = 2; #uM ## setting the variables prot1 and prot2s total_prot2 = 2; # total protein2 in the cell syms prot1 prot2s positive; #prot2s = activated protein2 prot2 = total_prot2 - prot2s; # prot2 = unactivated protein2 ## setting the rate expressions (degradation rate, production rate etc) v0 = k0; v1 = vpa((k1 * prot2) / (j1 + prot2));       vm1 = vpa((km1 * prot2s) / (jm1 + prot2s));         v2 = vpa((k2 * prot1 * prot2s) / (j2 + prot2s));         vm3 = vpa((km3 * prot1 * prot2s) / (jm3 + prot2s)); ## 2 steady state equations to be solved by vpasolve etc... ss_prot1 = v0 - v2 - kd*prot1 == 0; ss_prot2s = v1 - vm1 - vm3 == 0; equations = [ss_prot1, ss_prot2]; variables = [prot1, prot2s]; ## an update here prot2s [sol_prot1 sol_prot2] = vpasolve(equations, variables) And I got the following Python exception: TypeError: bad operand type for abs(): 'MutableDenseMatrix'     occurred at line 20 of the Python code block Is there probably another way to vpasolve? I tried fsolve before but it needs initial values so it gives me only 1 answer for prot1 and 1 answer for prot2s for a particular start value for prot1 and prot2s
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 Am 30. Mai 2016 17:45:37 MESZ, schrieb sam kjm <[hidden email]>: >Thanks for pointing that out! > >My updated codes are as follows: >## Constant parameters >k0 = 0.1; #uM/min >kd = 0.05; #/min >k1 = 0.6; #uM/min >j1 = 0.1; #uM >km1 = 0.2; #uM/min >jm1 = 0.1; #uM >k2 = 0.4; #/min >j2 = 0.1;#uM >km3 = 7.05;# /min >jm3 = 2; #uM > > > >## setting the variables prot1 and prot2s >total_prot2 = 2; # total protein2 in the cell >syms prot1 prot2s positive; #prot2s = activated protein2 >prot2 = total_prot2 - prot2s; # prot2 = unactivated protein2 > > > >## setting the rate expressions (degradation rate, production rate etc) >v0 = k0; >v1 = vpa((k1 * prot2) / (j1 + prot2));       >vm1 = vpa((km1 * prot2s) / (jm1 + prot2s));         >v2 = vpa((k2 * prot1 * prot2s) / (j2 + prot2s));         >vm3 = vpa((km3 * prot1 * prot2s) / (jm3 + prot2s)); > > > >## 2 steady state equations to be solved by vpasolve etc... >ss_prot1 = v0 - v2 - kd*prot1 == 0; >ss_prot2s = v1 - vm1 - vm3 == 0; > > >equations = [ss_prot1, ss_prot2]; >variables = [prot1, prot2s]; ## an update here prot2s >[sol_prot1 sol_prot2] = vpasolve(equations, variables) > > > >And I got the following >Python exception: TypeError: bad operand type for abs(): >'MutableDenseMatrix' >    occurred at line 20 of the Python code block > >Is there probably another way to vpasolve? I tried fsolve before but it >needs initial values so it gives me only 1 answer for prot1 and 1 >answer for >prot2s for a particular start value for prot1 and prot2s > > > > > >-- >View this message in context: >http://octave.1599824.n4.nabble.com/vpasolve-to-find-all-real-roots-for-multiple-nonlinear-equations-and-multiple-variables-tp4677276p4677279.html>Sent from the Octave - General mailing list archive at Nabble.com. > >_______________________________________________ >Help-octave mailing list >[hidden email] >https://lists.gnu.org/mailman/listinfo/help-octaveDid you look at fsolve of the interval package? It will compute a coverage of any solutions in the search range, e. g., in the range [0, 2] for each variable. There are several examples in the package documentation. Oliver _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 In reply to this post by sam kjm On 30/05/16 08:45, sam kjm wrote: > equations = [ss_prot1, ss_prot2]; I pasted in your code and got: >> equations = [ss_prot1, ss_prot2]; error: 'ss_prot2' undefined near line 1 column 23 > Is there probably another way to vpasolve? I tried fsolve before but it > needs initial values so it gives me only 1 answer for prot1 and 1 answer for > prot2s for a particular start value for prot1 and prot2s You said "main aim is to find all real roots for 2 nonlinear equations".  This is hard problem in general (because nonlinear). Algorithm-wise, `vpasolve` is going to pretty much do what `fsolve` does.  It will also need a initial guess (I think it makes one up---like zero---if you don't specify it).  Roughly speaking, `vpasolve` is intended for use when you need more than 16 digits of precision from `fsolve`. `@sym/solve` in some cases can solve nonlinear equations symbolically (finding all solutions).  I would suggest trying that first.  But drop the `vpa` stuff.  And perhaps look at the warnings you're getting from converting all your constants to symbolic. best, Colin _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 BTW, I filed a bug about the printing problems (extra `--`) in some of your expressions.  Follow here if you wish: https://github.com/cbm755/octsympy/issues/458Also, `vpasolve` only supports scalar equation.  Documentation does not make that clear!  I filed a bug to either fix that or at least make the documentation clearer: https://github.com/cbm755/octsympy/issues/459best, Colin _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 In reply to this post by Oliver Heimlich I see... Thanks Oliver! I'd try the fsolve from the interval package
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 In reply to this post by Colin Macdonald-2 Thanks Colin! Now I understand Octave's vpasolve.. I'd try the @sym/solve function
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 On 30/05/16 17:53, sam kjm wrote: > Thanks Colin! Now I understand Octave's vpasolve.. I'd try the @sym/solve > function Good luck!  And when working with symbolic, you probably want `kn = sym(1)/20` instead of `kn = 0.05` which later gets turned into a sym. best, Colin _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 In reply to this post by sam kjm Am 31. Mai 2016 02:46:31 MESZ, schrieb sam kjm <[hidden email]>: >I see... Thanks Oliver! I'd try the fsolve from the interval package > > > >-- >View this message in context: >http://octave.1599824.n4.nabble.com/vpasolve-to-find-all-real-roots-for-multiple-nonlinear-equations-and-multiple-variables-tp4677276p4677284.html>Sent from the Octave - General mailing list archive at Nabble.com. > >_______________________________________________ >Help-octave mailing list >[hidden email] >https://lists.gnu.org/mailman/listinfo/help-octaveThe interval fsolve function is an excellent option for the problem described here. However, its functionality is intimidating if you haven't used interval arithmetic before. Let me give more guidance. 1, look at the first fsolve example with parameter estimation in the package documentation. 2, exchange the function with your state function f and solve that for f = 0. 3, The first output argument of fsolve is probably useless in your case. You want to plot the second and third output as can be seen in the later examples. They will give you a guaranteed inner and outer approximation for the solution set. 4, If the approximation isn't accurate enough (e.g. inner approximation is the empty set and outer approximation is the whole search range), further knowledge of interval analysis is required to fine tune the algorithm and state function. You may ping back if you need help with that. Oliver _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 Thanks Oliver for the guidance! I think I managed  to get some results. However I met some problems along the way again. I have 2 separate code files: 1) My function file ("steady5.m") function steadystate = steady5(y, total_prot2)     ## Fixed parameters     k0 = 0.1; #uM/min     kd = 0.05; #/min     k1 = 0.6; #uM/min     j1 = 0.1; #uM     km1 = 0.2; #uM/min     jm1 = 0.1; #uM     k2 = 0.4; #/min     j2 = 0.1; #uM     km3 = 7.05; #/min     jm3 = 2; #uM     ## Unknowns to be solved (prot1, prot2s)     prot1 = y(1)     prot2s = y(2)     prot2 = total_prot2 - prot2s;       ## setting the rate expressions (degradation rate, production rate etc)     v0 = k0;     v1 = (k1 * prot2) / (j1 + prot2);           vm1 = (km1 * prot2s) / (jm1 + prot2s);             v2 = (k2 * prot1 * prot2s) / (j2 + prot2s);             vm3 = (km3 * prot1 * prot2s) / (jm3 + prot2s);       ## 2 steady state equations to be solved by fsolve etc...     steadystate = zeros(2,5);     ss_prot1 = v0 - v2 - kd*prot1 ;     ss_prot2s = v1 - vm1 - vm3 ;       steadystate = [ss_prot1; ss_prot2s];   end 2) My 2nd file contains the solve function with variables ("call_steady5") clear;clc;clf; total_prot2 = 0; while total_prot2 < 1     disp(total_prot2);     y = fsolve(@(y) steady5(y, total_prot2), infsup ([0;0], [5;5]), optimset("display", "off"));     disp(y);     total_prot2 = total_prot2 + 0.5; end 3) I got the results i think. But fsolve displays a lot of iterations before I get the final solution through disp(y). Unless I actually did not get the solutions? Plus what if I want to get >2 solutions? I have some that should have 3 solutions but I didn't manage to replicate that.  Is it determined by the initial values infsup([], [], []) too? Below 0 --> this part here is disp(total_protein2) p53 = [0, 5] AKTs = [0, 5] p53 = [0, 2.5] AKTs = [0, 5] p53 = [2.5, 5] AKTs = [0, 5] p53 = [0, 2.5] AKTs = [0, 2.5] p53 = [0, 2.5] AKTs = [2.5, 5] p53 = [0, 1.25] AKTs = [0, 2.5] p53 = [0, 1.25] AKTs = [2.5, 5] p53 = [1.25, 2.5] AKTs = [0, 2.5] p53 = [1.25, 2.5] AKTs = [2.5, 5] p53 = [0, 1.25] AKTs = [0, 1.25] p53 = [0, 1.25] AKTs = [2.5, 3.75] p53 = [1.25, 2.5] AKTs = [0, 1.25] p53 = [0, 1.25] AKTs = [1.25, 2.5] p53 = [0, 1.25] AKTs = [3.75, 5] p53 = [1.25, 2.5] AKTs = [1.25, 2.5] p53 = [0, 0.625] AKTs = [0, 1.25] p53 = [0, 0.625] AKTs = [2.5, 3.75] p53 = [1.25, 1.875] AKTs = [0, 1.25] p53 = [0, 0.625] AKTs = [1.25, 2.5] p53 = [0, 0.625] AKTs = [3.75, 5] p53 = [0.625, 1.25] AKTs = [0, 1.25] p53 = [0.625, 1.25] AKTs = [2.5, 3.75] p53 = [1.875, 2.5] AKTs = [0, 1.25] p53 = [0.625, 1.25] AKTs = [1.25, 2.5] p53 = [0.625, 1.25] AKTs = [3.75, 5] p53 = [0, 0.625] AKTs = [0, 0.625] p53 = [0, 0.625] AKTs = [2.5, 3.125] p53 = [1.25, 1.875] AKTs = [0, 0.625] p53 = [0, 0.625] AKTs = [1.25, 1.875] p53 = [0, 0.625] AKTs = [3.75, 4.375] p53 = [0.625, 1.25] AKTs = [0, 0.625] p53 = [1.875, 2.5] . . . . . AKTs <8A><82> [0.0097656, 0.019532] p53 <8A><82> [0.24414, 0.25391] AKTs <8A><82> [0.81054, 0.82032] p53 <8A><82> [0.40039, 0.41016] AKTs <8A><82> [0.10742, 0.11719] p53 <8A><82> [0.36132, 0.3711] AKTs <8A><82> [0.10742, 0.11719] p53 <8A><82> [0.24414, 0.25391] AKTs <8A><82> [0.8496, 0.85938] p53 <8A><82> [0.24414, 0.25391] AKTs <8A><82> [0.77148, 0.78125] p53 <8A><82> [0.34179, 0.35157] AKTs <8A><82> [0.10742, 0.11719] p53 <8A><82> [0.41992, 0.42969] AKTs <8A><82> [0.10742, 0.11719] p53 <8A><82> [0.38085, 0.39063] AKTs <8A><82> [0.10742, 0.11719]    [0.23437, 2.002]        [0, 0.88868] etc..
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 I see! Thanks loads for the jump starters!
Open this post in threaded view
|

Re: vpasolve to find all real roots for multiple nonlinear equations and multiple variables

 In reply to this post by Colin Macdonald-2 Hi Colin! I tried the same problem using symbolic methods this time. I managed to get the solutions I think. But something strange happened in the command window so I can't decipher the solutions. How do i eliminate the chevron identities? ## Constant parameters k0 = sym(1)/10; #uM/min kd = sym(1)/20; #/min k1 = sym(6)/10; #uM/min j1 = sym(1)/10; #uM km1 = sym(2)/10; #uM/min jm1 = sym(1)/10; #uM k2 = sym(4)/10; #/min j2 = sym(1)/10;#uM km3 = sym(141)/20;# /min jm3 = sym(2); #uM ## Setting the variables AKTtot = sym(2); syms p53 AKTs positive; AKT = AKTtot - AKTs; ##Setting rate expressions v0 = k0; v1 = (k1 * AKT) / (j1 + AKT); vm1 = (km1 * AKTs) / (jm1 + AKTs); v2 = (k2 * p53 * AKTs) / (j2 + AKTs); vm3 = (km3 * p53 * AKTs) / (jm3 + AKTs); ## Equations to be solved ssp53 = v0 - v2 - kd*p53 == 0; ssAKT = v1 - vm1 - vm3 == 0; solve(ssp53, ssAKT, p53, AKTs); Results: Waiting.................................. ans = {   [1,1] =     scalar structure containing the fields: AKTs = (sym)           <95>         <95>        <95>                __________________________________________________________________________________________________________________________       <95>               <95>                                                                             ____________________________________________           <95>              <95>  351983                            29755967                                 <95>  844328630599    <88> <9A>1607355029231483494015<8B><85><85><88>           <95>             <95>   <94><80><94><80><94><80><94><80><94><80><94><80> + <94><80><94><80><94><80> <94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94> <80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80> <94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94> <80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80> + 2<8B><85>3 <95>  <94> <80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80> + <94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94> <80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80>          <95>            <95>    294000                 ____________________________________________     <95><95>   62511750000000        6945750000000               <95>           <95>                           <95>  844328630599    <88><9A>1607355029231483494015<8B><85><85><88>                                                         <95>          <95>               248062500<8B><85>3 <95>  <94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80> + <94><80><94><80><94><80> <94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94> <80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80>                                          <95>  551   <95><95>                          <95><95>   62511750000000         6945750000000                                           <95><95>  <94><80><94><80><94><80> - <94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80> <94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94> <80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80> <94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94> <80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80> <94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94> <80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80> <94><80><94><80><94><80><94><80><94><80> - <94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80><94><80>   840                                                                   2   ...... and many more of the  interspersed with numbers (my solutions i think)