Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a value from solution set returned as finiteset by Sympy

Tags:

python

sympy

I`m creating a script in Python Sympy library and trying to access the result returned by solveset() and linsolve() functions. My problem is that the object returned by these functions is of type finiteset and I want to select some results automaticaly to re-enter it in other equations. Any body could help me?

An example: I create a list of equations with two unknown variables:

>>> a1, a2 = symbols('a1, a2') >>> eq2_1 = Eq(-3*a1/10 - 3*a2/20 + 1/12) >>> eq2_2 = Eq(-3*a1/20 - 13*a2/105 + 1/20) >>> lista = [eq2_1,eq2_2] >>> str(lista) [-3*a1/10 - 3*a2/20 + 1/12, -3*a1/20 - 13*a2/105 + 1/20] 

Then a solve it with the linsolve() method.

>>> a = linsolve(lista,a1,a2) >>> a {(71/369, 7/41)}  

The result is correct, but I'm unable to get these results in to a variable.

O tried dics, lists, tuples, indexing commands, but always return the error. "Finiteset objects has no attribute 'command'"

like image 697
Plinio Bueno Andrade Silva Avatar asked Jul 17 '16 05:07

Plinio Bueno Andrade Silva


1 Answers

I found the sympy library way in this link http://docs.sympy.org/latest/tutorial/manipulation.html

Use .args atribute in the function or result object. If I have a function:

>>>func = Eq(u(x),−x+sin(x))  >>>func u(x) = -x + sin(x) >>>func.args[0]  u(x) >>>func.args[1] -x+sin(x) 

The same applies for a result that is a finite set type.

like image 158
Plinio Bueno Andrade Silva Avatar answered Sep 24 '22 09:09

Plinio Bueno Andrade Silva