1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pipenv で sympy を使って整式の次数と定数項を得る方法

Posted at
pipenv --python 3.8
pipenv install sympy
vim hoge.py

from sympy import *
from sympy.abc import x,y

expr = '-2*x + 3*y + x**2 + 5*x -y'

print("元の式")
print(expr)
print("")
expr = sympify(expr)

print("同類項にまとめる")
print(expand(expr))
print("")

print("x の次数")
print(degree(expr,x))
print("")

print("x の定数項")
print(expr.coeff(x,0))
print("")
pipenv run python hoge.py
元の式
-2*x + 3*y + x**2 + 5*x -y

同類項にまとめる
x**2 + 3*x + 2*y

x の次数
2

x の定数項
2*y
1
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?