Solveset is not indexable, so try converting to list. What surprised me is
that it is not like regular python set:
ptipython
Python 3.5.1 |Anaconda custom (64-bit)| (default, Dec 7 2015, 11:16:01)
Type "copyright", "credits" or "license" for more information.
IPython 4.2.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import sympy
In [2]: sympy.__version__
Out[2]: '1.0'
In [3]: x=sympy.symbols('x',real=True)
...: e,m=sympy.symbols('e,m',positive=True)
...: sympy.solveset(sympy.sqrt(2*e*m-(x*m)**2),x)
Out[3]: {-sqrt(2)*sqrt(e)/sqrt(m), sqrt(2)*sqrt(e)/sqrt(m)}
In [4]: _
Out[4]: {-sqrt(2)*sqrt(e)/sqrt(m), sqrt(2)*sqrt(e)/sqrt(m)}
In [5]: sols=_
In [6]: type(sols)
Out[6]: sympy.sets.sets.FiniteSet
In [7]: sols.pop()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-188fe3e26bd2> in <module>()
----> 1 sols.pop()
AttributeError: 'FiniteSet' object has no attribute 'pop'
In [8]: list(sols)
Out[8]: [sqrt(2)*sqrt(e)/sqrt(m), -sqrt(2)*sqrt(e)/sqrt(m)]
On Tuesday, May 17, 2016 at 9:24:47 PM UTC-5, chaowen guo wrote:
>
> Hi:
>
> In sympy1.0, it is recommended to use solveset to solve equation, but how
> to get the element of the solution?
>
> For example:
>
> import sympy
> x=sympy.symbols('x',real=True)
> e,m=sympy.symbols('e,m',positive=True)
> sympy.solveset(sympy.sqrt(2*e*m-(x*m)**2),x)
>
> I want to get the first and second solution individually to do further
> calculation, but I can not directly use [0] and [1], so how to get
> individual element?
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/733f8e55-e2ad-438e-bd2a-792524801685%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.