Solving a system of equation with Sympy, python2.7
<p>I want to solve a system of equations. But I want to be able to precise the value to "get", and as a function of "what".</p>

<p>To better understand, I take an exemple from <a href="http://stackoverflow.com/questions/22156709/solving-system-of-nonlinear-equations-with-python#_=_">here</a>, wich I modfified:</p>

<pre><code>import sympy as sp
x, y, z = sp.symbols('x, y, z')
rho, sigma, beta = sp.symbols('rho, sigma, beta')
f1 = sigma * (y - x)
f2 = x * (rho - z) - y
f3 = x * y - beta * z
print sp.solvers.solve((f1, f2, f3), (x, y, z))
</code></pre>

<p>in </p>

<pre><code>import sympy as sp
x, y, z, w = sp.symbols('x, y, z, w')
rho, sigma, beta = sp.symbols('rho, sigma, beta')
f1 = sigma * (y - x)
f2 = x * (rho - z) - y
f3 = x * y - beta * w
f4 = z - w
print sp.solvers.solve((f1, f2, f3, f4), (x, y, z))
</code></pre>

<p>So, as you can see, I replace <strong>z</strong> by <strong>w</strong> in the last equation and I add a new to precise <strong>z = w</strong>. 
But, <strong>sympy (on python 2.7) is unable to solve this new system of equation!!</strong></p>

<p><em>So my question:</em> How to get the result for x, y, z as a function of rho, sigma, beta. And more generally, how do we precise the variable "response variable".</p>

<p><em>I think that could be very helpfull because, often, you don't want to developp your system of equation before asking python to solve it.</em></p>

<p>In the same way, if I take a more complex example:</p>

<pre><code>import sympy as sp
x, y, z, w, u = sp.symbols('x, y, z, w, u')
rho, sigma, beta = sp.symbols('rho, sigma, beta')
f1 = sigma * (y - x)
f2 = x * (rho - u) - y
f3 = x * y - beta * w
f4 = z - w
f5 = w - u
print sp.solvers.solve((f1, f2, f3, f4, f5), (x, y, z))
</code></pre>

<p>The response I get is: </p>

<pre><code>[]
</code></pre>

<p>But as you see I have z = w = u
Son I should get the same answer!</p>

<p>Your code is giving following error:  </p>

<blockquote>
  <p>Traceback (most recent call last):
    File "C:\temp\equation1.py", line 37, in  f3 = x * y - beta * w  NameError: name 'w' is not defined</p>
</blockquote>

<p>Hence we pull symbol 'w' from  sympy symbols as below
<code>x, y, z, w = sp.symbols('x, y, z, w')</code> </p>

<p>You also mentioned you are trying to add  <code>z = w</code> , so once we add that to your code, it works.</p>

<p><strong>Working Code:</strong></p>

<pre><code>import sympy as sp
x, y, z, w = sp.symbols('x, y, z, w')
rho, sigma, beta = sp.symbols('rho, sigma, beta')
z = w
f1 = sigma * (y - x)
f2 = x * (rho - z) - y
f3 = x * y - beta * w
f4 = z - w
print sp.solvers.solve((f1, f2, f3, f4), (x, y, z, w))
</code></pre>

<p><strong>Output:</strong>  </p>

<pre><code>Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
&gt;&gt;&gt; ================================ RESTART ================================
&gt;&gt;&gt; 
[(0, 0, 0), (-sqrt(beta*rho - beta), -sqrt(beta*(rho - 1)), rho - 1), (sqrt(beta*rho - beta), sqrt(beta*(rho - 1)), rho - 1)]
&gt;&gt;&gt; 
</code></pre>

python python-2.7 sympy equation equation-solving