ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 07 Jan 2012 15:22:56 -0600Solving a simple system of equationshttp://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/Hey Guys,
New to Sage and just trying to solve a simple system of equations. The system is below:
x,y,z,w,ha,hb,e,c = var('x y z w ha hb e c')
f1 = (c*(x+y)*(ha-x))-(e*x)
f2 = (c*(z+w)*(ha-x-z))-(c*z*(x+y)) - (e*z)
f3 = (c*(x+y)*(hb-y-w))-(c*y*(z+w)) - (e*y)
f4 = (c*(z+w)*(hb-w))-(e*w)
I want to find the equilibrium solutions, solving for x, y, z, w, when equations f1-f4 are equal to zero. So I try:
solve([f1==0,f2==0,f3==0,f4==0],x,y,z,w)
Unfortunately this causes Sage to hang (or it takes a remarkably long time to solve that I interrupt the process). This problem shouldn't be difficult to solve, but I am at a loss as to what to do. Perhaps I am going about this the wrong way??
Sat, 07 Jan 2012 05:15:49 -0600http://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/Answer by Volker Braun for <p>Hey Guys,</p>
<p>New to Sage and just trying to solve a simple system of equations. The system is below:</p>
<pre><code>x,y,z,w,ha,hb,e,c = var('x y z w ha hb e c')
f1 = (c*(x+y)*(ha-x))-(e*x)
f2 = (c*(z+w)*(ha-x-z))-(c*z*(x+y)) - (e*z)
f3 = (c*(x+y)*(hb-y-w))-(c*y*(z+w)) - (e*y)
f4 = (c*(z+w)*(hb-w))-(e*w)
</code></pre>
<p>I want to find the equilibrium solutions, solving for x, y, z, w, when equations f1-f4 are equal to zero. So I try:</p>
<pre><code>solve([f1==0,f2==0,f3==0,f4==0],x,y,z,w)
</code></pre>
<p>Unfortunately this causes Sage to hang (or it takes a remarkably long time to solve that I interrupt the process). This problem shouldn't be difficult to solve, but I am at a loss as to what to do. Perhaps I am going about this the wrong way??</p>
http://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/?answer=13099#post-id-13099You should be using Groebner bases (and the *Singular* interface) instead of general purpose symbolics (via *Maxima*) for systems of polynomial equations. The standard way of doing what you want is to compute a lexicographic Groebner basis along the lines of what I [commented here](http://ask.sagemath.org/question/403/method-for-solving-a-large-system-of-under#762).Sat, 07 Jan 2012 15:22:56 -0600http://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/?answer=13099#post-id-13099Answer by Emil Widmann for <p>Hey Guys,</p>
<p>New to Sage and just trying to solve a simple system of equations. The system is below:</p>
<pre><code>x,y,z,w,ha,hb,e,c = var('x y z w ha hb e c')
f1 = (c*(x+y)*(ha-x))-(e*x)
f2 = (c*(z+w)*(ha-x-z))-(c*z*(x+y)) - (e*z)
f3 = (c*(x+y)*(hb-y-w))-(c*y*(z+w)) - (e*y)
f4 = (c*(z+w)*(hb-w))-(e*w)
</code></pre>
<p>I want to find the equilibrium solutions, solving for x, y, z, w, when equations f1-f4 are equal to zero. So I try:</p>
<pre><code>solve([f1==0,f2==0,f3==0,f4==0],x,y,z,w)
</code></pre>
<p>Unfortunately this causes Sage to hang (or it takes a remarkably long time to solve that I interrupt the process). This problem shouldn't be difficult to solve, but I am at a loss as to what to do. Perhaps I am going about this the wrong way??</p>
http://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/?answer=13097#post-id-13097I replaced cz with c * z and cy with c * y and got a (somewhat lengthy) solution immediatly. Does this solve it?Sat, 07 Jan 2012 06:06:31 -0600http://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/?answer=13097#post-id-13097Comment by Balder for <p>I replaced cz with c * z and cy with c * y and got a (somewhat lengthy) solution immediatly. Does this solve it?</p>
http://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/?comment=20581#post-id-20581Hey, thanks for the answer. Unfortunately I am not following what you did. Where exactly did you make the change? In my original code I see no cz or cy...??Sat, 07 Jan 2012 07:25:45 -0600http://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/?comment=20581#post-id-20581Answer by Emil Widmann for <p>Hey Guys,</p>
<p>New to Sage and just trying to solve a simple system of equations. The system is below:</p>
<pre><code>x,y,z,w,ha,hb,e,c = var('x y z w ha hb e c')
f1 = (c*(x+y)*(ha-x))-(e*x)
f2 = (c*(z+w)*(ha-x-z))-(c*z*(x+y)) - (e*z)
f3 = (c*(x+y)*(hb-y-w))-(c*y*(z+w)) - (e*y)
f4 = (c*(z+w)*(hb-w))-(e*w)
</code></pre>
<p>I want to find the equilibrium solutions, solving for x, y, z, w, when equations f1-f4 are equal to zero. So I try:</p>
<pre><code>solve([f1==0,f2==0,f3==0,f4==0],x,y,z,w)
</code></pre>
<p>Unfortunately this causes Sage to hang (or it takes a remarkably long time to solve that I interrupt the process). This problem shouldn't be difficult to solve, but I am at a loss as to what to do. Perhaps I am going about this the wrong way??</p>
http://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/?answer=13098#post-id-13098I think your original question was edited, because when I answered before there were the lines
f2 = (c(z+w)(ha-x-z))-(cz*(x+y)) - (e*z)
f3 = (c(x+y)(hb-y-w))-(cy*(z+w)) - (e*y)
I added multiplication signs between cz and cy and pasted the following code into the cell
x,y,z,w,ha,hb,e,c = var('x y z w ha hb e c')
f1 = (c(x+y)(ha-x))-(e*x)
f2 = (c(z+w)(ha-x-z))-(c*z(x+y)) - (e*z)
f3 = (c(x+y)(hb-y-w))-(c*y(z+w)) - (e*y)
f4 = (c(z+w)(hb-w))-(e*w)
solve([f1==0,f2==0,f3==0,f4==0],x,y,z,w)
I then get the answer
[[x == (c*e*hb - e^2*hb + (2*c^2 - e^3 + (c^2 + c)*e - e^2 + 3*c +
1)*ha)/(4*c^2 - e^4 + (c^2 - 1)*e^2 - 2*e^3 + 2*(2*c^2 + c)*e + 4*c +
1), y == -(e^3*hb - (c*hb - hb)*e^2 - c*e*hb - (c*e^2 - (c^2 - 2*c -
1)*e - 2*c^2 - c)*ha)/(4*c^2 - e^4 + (c^2 - 1)*e^2 - 2*e^3 + 2*(2*c^2 +
c)*e + 4*c + 1), z == (c*e^2*hb - 2*c^2*hb - (c^2*hb - 2*c*hb - hb)*e +
((c - 1)*e^2 - e^3 + c*e)*ha - c*hb)/(4*c^2 - e^4 + (c^2 - 1)*e^2 -
2*e^3 + 2*(2*c^2 + c)*e + 4*c + 1), w == -(e^3*hb - 2*c^2*hb + e^2*hb -
(c*e - e^2)*ha - (c^2*hb + c*hb)*e - 3*c*hb - hb)/(4*c^2 - e^4 + (c^2 -
1)*e^2 - 2*e^3 + 2*(2*c^2 + c)*e + 4*c + 1)]]
I just see that * sign is removed from normal text postings on this site, so your original system probably contained all *. In the current form with all * I get no solution either. - sorry
PS: Question to the site admins: Is it a bug or a feature of this site that * is removed?
Sat, 07 Jan 2012 09:16:30 -0600http://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/?answer=13098#post-id-13098Comment by DSM for <p>I think your original question was edited, because when I answered before there were the lines </p>
<pre><code>f2 = (c(z+w)(ha-x-z))-(cz*(x+y)) - (e*z)
f3 = (c(x+y)(hb-y-w))-(cy*(z+w)) - (e*y)
</code></pre>
<p>I added multiplication signs between cz and cy and pasted the following code into the cell</p>
<pre><code>x,y,z,w,ha,hb,e,c = var('x y z w ha hb e c')
f1 = (c(x+y)(ha-x))-(e*x)
f2 = (c(z+w)(ha-x-z))-(c*z(x+y)) - (e*z)
f3 = (c(x+y)(hb-y-w))-(c*y(z+w)) - (e*y)
f4 = (c(z+w)(hb-w))-(e*w)
solve([f1==0,f2==0,f3==0,f4==0],x,y,z,w)
</code></pre>
<p>I then get the answer</p>
<pre><code>[[x == (c*e*hb - e^2*hb + (2*c^2 - e^3 + (c^2 + c)*e - e^2 + 3*c +
1)*ha)/(4*c^2 - e^4 + (c^2 - 1)*e^2 - 2*e^3 + 2*(2*c^2 + c)*e + 4*c +
1), y == -(e^3*hb - (c*hb - hb)*e^2 - c*e*hb - (c*e^2 - (c^2 - 2*c -
1)*e - 2*c^2 - c)*ha)/(4*c^2 - e^4 + (c^2 - 1)*e^2 - 2*e^3 + 2*(2*c^2 +
c)*e + 4*c + 1), z == (c*e^2*hb - 2*c^2*hb - (c^2*hb - 2*c*hb - hb)*e +
((c - 1)*e^2 - e^3 + c*e)*ha - c*hb)/(4*c^2 - e^4 + (c^2 - 1)*e^2 -
2*e^3 + 2*(2*c^2 + c)*e + 4*c + 1), w == -(e^3*hb - 2*c^2*hb + e^2*hb -
(c*e - e^2)*ha - (c^2*hb + c*hb)*e - 3*c*hb - hb)/(4*c^2 - e^4 + (c^2 -
1)*e^2 - 2*e^3 + 2*(2*c^2 + c)*e + 4*c + 1)]]
</code></pre>
<p>I just see that * sign is removed from normal text postings on this site, so your original system probably contained all *. In the current form with all * I get no solution either. - sorry</p>
<p>PS: Question to the site admins: Is it a bug or a feature of this site that * is removed?</p>
http://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/?comment=20579#post-id-20579@Emil Widmann: I'm not a site admin, but I can explain. It's a feature, although it's often troublesome for us mathy types: the asterisk is used to put things in italics (e.g. *fred*). I edited the original post to use the code blocks to get the formatting right when I saw that it had led to a misunderstanding.Sat, 07 Jan 2012 12:05:48 -0600http://ask.sagemath.org/question/8613/solving-a-simple-system-of-equations/?comment=20579#post-id-20579