Skip to content

Instantly share code, notes, and snippets.

@devlights
Created May 5, 2018 14:16
Show Gist options
  • Save devlights/f2e49549afbec3c15b1b113412540204 to your computer and use it in GitHub Desktop.
Save devlights/f2e49549afbec3c15b1b113412540204 to your computer and use it in GitHub Desktop.
[python][sympy] python の sympy つかって因数分解
import sympy
# x を定義
x = sympy.Symbol('x')
# 式定義
# x^3 - 2x^2 - 5x + 6
expr = x**3 - 2*(x**2) - 5*x + 6
print(expr)
# 因数分解
result = sympy.factor(expr)
print(result)
# 展開
print(sympy.expand(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment