'Sympy returns empty result

I am attempting a very simple sympy example as following ;

from sympy import *
x,y,z = symbols('x,y,z', real=True)
expr = 256 * exp(-Pow((x-(y/2)/(z/2)),2))
solve(expr,x)

trying to get x in terms of y and z. Execution results in an empty list. What am I doing wrong ?



Solution 1:[1]

Let fx = Symbol('fx', real=True). You will get solve(exp(fx),fx) == [] because there is no real value of fx that can make exp(fx) zero. If there were such a value, say fx = 2 then you could try solve(fx - 2, x) to find the value for x...but if there is no value for fx there is no value you can find for x.

Solution 2:[2]

Your equation doesn't have any solutions for x so solve returns an empty list. Here is your equation:

In [2]: expr
Out[2]: 
             2
      ?    y? 
     -?x - ?? 
      ?    z? 
256??  

When you pass that to solve you are asking "for what values of x is this expression equal to zero?". The exponential function exp(t) is nonzero for all possible complex numbers t. Since there are no finite values of x for which the given expression is zero solve returns an empty list meaning that there are no solutions:

In [3]: solve(expr, x)
Out[3]: []

If you make an equation that actually has solutions then solve can potentially find them for you:

In [6]: eq = Eq(expr, 1)

In [7]: eq
Out[7]: 
             2    
      ?    y?     
     -?x - ??     
      ?    z?     
256??          = 1

In [8]: solve(eq, x)
Out[8]: 
?y          ________  y          ________?
?? - 2??2??? log(2) , ? + 2??2??? log(2) ?
?z                    z                  ?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 smichr
Solution 2 Oscar Benjamin