Skip to content

Instantly share code, notes, and snippets.

@hcastillaq
Created August 13, 2018 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hcastillaq/9f0ff8fc27188cf7e2836cd3bc660740 to your computer and use it in GitHub Desktop.
Save hcastillaq/9f0ff8fc27188cf7e2836cd3bc660740 to your computer and use it in GitHub Desktop.
validar que una solución sea un numero real con sympy
"""
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