.. toctree:: =================== Sympyによる代数計算 =================== 代数計算や微分積分、微分方程式まで代数的に解いてくれます。 http://docs.sympy.org/latest/index.html 代数計算は、代数として使う記号を定義して計算させるだけなので直感的に利用 できるかと思います。 計算例 ====== sympy.symbols()で代数計算する定数変数を定義します。微分方程式を解くと きは、sympy.Function()で関数を定義し、sympy.Eq()で微分方程式の左辺と右 辺を定義します。微分方程式を定義したらsympy.dsolve()で解いてもらいます。 数式は、sympy.latex()に渡せばlatex形式で出力することもできます。 .. literalinclude:: arithmetic.py :caption: arithmetic.py 出力結果は、次のような式になります。 因数分解 -------- .. math:: \left(x - 5\right) \left(x + 3\right) 微分 ---- .. math:: 2 x - 2 積分 ---- .. math:: \frac{x^{3}}{3} - x^{2} - 15 x 定積分 ------ .. math:: \frac{250}{3} 行列式 ------ .. math:: a d - b c 行列積 ------ .. math:: \left[\begin{matrix}a + 3 b & 2 a - b\\c + 3 d & 2 c - d\end{matrix}\right] 逆行列 ------ .. math:: \left[\begin{matrix}\frac{d}{a d - b c} & - \frac{b}{a d - b c}\\- \frac{c}{a d - b c} & \frac{a}{a d - b c}\end{matrix}\right] 1次の化学反応の微分方程式の解 ----------------------------- .. math:: c{\left (t \right )} = C_{1} e^{- k t} 2次の化学反応の微分方程式の解 ----------------------------- .. math:: c{\left (t \right )} = \frac{1}{C_{1} + k t} ポテンシャル場のない1次元シュレディンガー方程式の解 --------------------------------------------------- .. math:: :nowrap: \begin{equation*} x{\left (x \right )} = C_{1} e^{- x \sqrt{- E}} + C_{2} e^{x \sqrt{- E}} \end{equation*}