Created
August 13, 2018 18:16
-
-
Save hcastillaq/9f0ff8fc27188cf7e2836cd3bc660740 to your computer and use it in GitHub Desktop.
validar que una solución sea un numero real con sympy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
recibe como parámetro un arreglo de soluciones, | |
las valida y retorna la solución, retorna None para soluciones con parte imaginaria | |
""" | |
def getSolution(data): | |
sol = None | |
#recorremos cada solucion del arreglo | |
for val in data: | |
val = val.evalf() #evaluamos la solucion, nos deja un numero | |
#validamos que la solucion evaluada sea mayor que 0 y tambien un numero real | |
if val > 0 and sympify(val).is_real: | |
sol = val | |
break | |
return sol |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment