2019年9月21日土曜日

数学 - Python - 微分積分学 - 微分法の公式 - 微分法の公式 - 関数の商の導関数

1. $\begin{array}{l}\frac{d}{\mathrm{dx}}\frac{{a}^{2}-{x}^{2}}{{a}^{2}+{x}^{2}}\\ =\frac{-2x\left({a}^{2}+{x}^{2}\right)-\left({a}^{2}-{x}^{2}\right)·2x}{{\left({a}^{2}+{x}^{2}\right)}^{2}}\\ =\frac{-2x\left({a}^{2}+{x}^{2}+{a}^{2}-{x}^{2}\right)}{{\left({a}^{2}+{x}^{2}\right)}^{2}}\\ =\frac{-4{a}^{2}x}{{\left({a}^{2}+{x}^{2}\right)}^{2}}\end{array}$

2. $\begin{array}{l}\frac{d}{\mathrm{dx}}\frac{\sqrt{x}}{1-{x}^{3}}\\ =\frac{\frac{1}{2\sqrt{x}}\left(1-{x}^{3}\right)-\sqrt{x}\left(-3{x}^{2}\right)}{{\left(1-{x}^{3}\right)}^{2}}\\ =\frac{1-{x}^{3}+6{x}^{3}}{2\sqrt{x}{\left(1-{x}^{3}\right)}^{2}}\\ =\frac{1+5{x}^{3}}{2\sqrt{x}{\left(1-{x}^{3}\right)}^{2}}\end{array}$

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, sqrt, Derivative
from unittest import TestCase, main

print('2.')

class MyTest(TestCase):
def setUp(self):
pass

def tearDown(self):
pass

def test(self):
x, a = symbols('x, a')
fs = [(a ** 2 - x ** 2) / (a ** 2 + x ** 2),
sqrt(x) / (1 - x ** 3)]
dfs = [-4 * a ** 2 * x / (a ** 2 + x ** 2) ** 2,
(1 + 5 * x ** 3) / (2 * sqrt(x) * (1 - x ** 3) ** 2)]
for f, df in zip(fs, dfs):
self.assertEqual(Derivative(f, x, 1).doit().simplify(),
df.simplify())

if __name__ == '__main__':
main()


$./sample2.py 2. . ---------------------------------------------------------------------- Ran 1 test in 0.341s OK$