0
0

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 1 year has passed since last update.

python3 数学ⅰ 展開と因数分解

Posted at

高校で使う数学の復習がてらpythonの勉強もしていきます。今回は数学ⅰの数と式から展開と因数分解をやります。

まずsympyというライブラリをpipコマンドで入れます

pip install sympy

式の展開からやっていきます。
sympy.Symbol()で文字を定義し、sympy.expand()で式を展開します。

import sympy

x = sympy.Symbol('x')#文字xを定義
y = sympy.Symbol('y')

ex = (x + y)*(2*x + 2*y)#式を定義
f = sympy.expand(ex)#式の展開
print(f)

2x**2 + 4xy + 2y**2と出力されます
つぎは因数分解
sympy.factor()で因数分解できます

import sympy

x = sympy.Symbol('x')
y = sympy.Symbol('y')

ex = 2*x**2 + 5*x*y + 3*y**2
f = sympy.factor(ex)
print(f)

(x + y)(2x + 3*y)と出力されます

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?