学習環境
- Surface、Surface ペン(端末)
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad Pro 10.5 + Apple Pencil
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
微分積分学 (ちくま学芸文庫) (吉田 洋一(著)、筑摩書房)のⅡ.(微分法の公式)、6.(導関数の求め方)、演習問題II、1、2、3、4、5、6、7、8、9、10、11、12、13、14、15の解答を求めてみる。
コード
Python 3
#!/usr/bin/env python3
from sympy import pprint, symbols, sqrt, root, Derivative, Rational
from unittest import TestCase, main
print('1-15.')
class MyTest(TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test(self):
x, a, b, c, m, n, p = symbols('x, a, b, c, m, n, p')
spam = [x ** 5 + 4 * x ** 3 + 7 * x + 3,
(a + b * x + c * x ** 2) / sqrt(x),
(3 * x + 2) / (1 + x + x ** 2),
(x - a) / ((x - b) * (x - c)),
x * (x + a) * (x + b),
1 / ((x - a) ** 2 + b ** 2) ** n,
sqrt(a ** 4 - x ** 4),
sqrt((x - 2) * (x - 3)),
sqrt(1 + 2 * x) / root(1 + 3 * x, 3),
sqrt((1 - root(x, 3)) / (1 + root(x, 3))),
(sqrt(a ** 2 + x ** 2) + (a ** 2 - x ** 2)) /
(sqrt(a ** 2 + x ** 2) - sqrt(a ** 2 - x ** 2)),
(a ** Rational(2, 3) - x ** Rational(2, 3)) ** Rational(3, 2),
1 / ((x + 1) ** m * (x + 3) ** n),
x ** m * (a + b * x ** n) ** p,
1 / (x + sqrt(x ** 2 + a ** 2))]
egg = [5 * x ** 4 + 12 * x ** 2 + 7,
(3 * c * x ** 2 + b * x - a) / (2 * x * sqrt(x)),
(1 - 4 * x - 3 * x ** 2) / (1 + x + x ** 2) ** 2,
(-x ** 2 + 2 * a * x - a * b + b * c - c * a) /
((x - b) ** 2 * (x - c) ** 2),
3 * x ** 2 + 2 * (a + b) * x + a * b,
- (n * ((x - a) ** 2 + b ** 2) ** (n - 1) * 2 * (x - a)) /
((x - a) ** 2 + b ** 2) ** (2 * n),
-2 * x ** 3 / sqrt(a ** 4 - x ** 4),
(2 * x - 5) / (2 * sqrt((x - 2) * (x - 3))),
(1 + 2 * x) ** -Rational(1, 2) * (1 + 3 * x) ** -Rational(1, 3) -
(1 + 2 * x) ** Rational(1, 2) * (1 + 3 * x) ** -Rational(4, 3),
-Rational(1, 3) * x ** -Rational(2, 3) *
1 / sqrt((1 - root(x, 3)) * (1 + root(x, 3))) *
1 / (1 + root(x, 3)),
-2 * a ** 2 * (sqrt(a ** 4 - x ** 4) + a ** 2) /
(x ** 3 * sqrt(a ** 4 - x ** 4)),
-(a ** Rational(2, 3) - x ** Rational(2, 3)) ** Rational(1, 2) *
x ** -Rational(1, 3),
-m * (x + 1) ** -(m - 1) * (x + 3) ** -n +
(x + 1) ** -m * (-n) * (x + 3) ** -(n - 1),
m * x ** (m - 1) * (a + b * x ** n) ** p +
x ** m * p * (a + b * x ** n) ** (p - 1) * b * x ** (n - 1),
-1 / ((x + sqrt(x ** 2 + a ** 2)) * sqrt(x ** 2 + a ** 2))]
for i, (s, t) in enumerate(zip(spam, egg), 1):
d = Derivative(s, x, 1).doit()
try:
self.assertEqual(d.factor(), t.factor())
except:
try:
self.assertEqual(d.simplify(), t.simplify())
except:
try:
self.assertEqual(d.expand(), t.expand())
except AssertionError as err:
for o in [f'{i}.', s.simplify(),
d.factor(), t]:
pprint(o)
print()
print()
if __name__ == '__main__':
main()
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
$ ./sample1.py
1-15.
10.
___________
╱ 3 ___
╱ 1 - ╲╱ x
╱ ─────────
╱ 3 ___
╲╱ ╲╱ x + 1
_______________
╱ ⎛3 ___ ⎞
╱ -⎝╲╱ x - 1⎠
╱ ─────────────
╱ 3 ___
╲╱ ╲╱ x + 1
──────────────────────────────
2/3 ⎛3 ___ ⎞ ⎛3 ___ ⎞
3⋅x ⋅⎝╲╱ x - 1⎠⋅⎝╲╱ x + 1⎠
-1
───────────────────────────────────────────────
_________________________
2/3 ╱ ⎛ 3 ___⎞ ⎛3 ___ ⎞ ⎛3 ___ ⎞
3⋅x ⋅╲╱ ⎝1 - ╲╱ x ⎠⋅⎝╲╱ x + 1⎠ ⋅⎝╲╱ x + 1⎠
11.
_________
2 2 ╱ 2 2
- a + x - ╲╱ a + x
───────────────────────────
_________ _________
╱ 2 2 ╱ 2 2
╲╱ a - x - ╲╱ a + x
⎛ _________ _________ _________ _____
⎜ 2 ╱ 2 2 2 ╱ 2 2 2 2 ╱ 2 2 2 ╱ 2
-x⋅⎝3⋅a ⋅╲╱ a - x - a ⋅╲╱ a + x + 2⋅a + x ⋅╲╱ a - x + x ⋅╲╱ a +
──────────────────────────────────────────────────────────────────────────────
2
_________ ⎛ _________ _________⎞
___________________ ╱ 2 2 ⎜ ╱ 2 2 ╱ 2 2 ⎟
╲╱ -(-a + x)⋅(a + x) ⋅╲╱ a + x ⋅⎝- ╲╱ a - x + ╲╱ a + x ⎠
____⎞
2 ⎟
x ⎠
──────
⎛ _________⎞
2 ⎜ 2 ╱ 4 4 ⎟
-2⋅a ⋅⎝a + ╲╱ a - x ⎠
──────────────────────────
_________
3 ╱ 4 4
x ⋅╲╱ a - x
13.
-m -n
(x + 1) ⋅(x + 3)
-m -n
-(x + 1) ⋅(x + 3) ⋅(m⋅x + 3⋅m + n⋅x + n)
───────────────────────────────────────────
(x + 1)⋅(x + 3)
1 - m -n -m 1 - n
- m⋅(x + 1) ⋅(x + 3) - n⋅(x + 1) ⋅(x + 3)
14.
p
m ⎛ n⎞
x ⋅⎝a + b⋅x ⎠
p
m ⎛ n⎞ ⎛ n n⎞
x ⋅⎝a + b⋅x ⎠ ⋅⎝a⋅m + b⋅m⋅x + b⋅n⋅p⋅x ⎠
────────────────────────────────────────
⎛ n⎞
x⋅⎝a + b⋅x ⎠
p - 1 p
m n - 1 ⎛ n⎞ m - 1 ⎛ n⎞
b⋅p⋅x ⋅x ⋅⎝a + b⋅x ⎠ + m⋅x ⋅⎝a + b⋅x ⎠
.
----------------------------------------------------------------------
Ran 1 test in 2.027s
OK
$
計算間違いしてる可能性があるけど、気にせず先に進めていくことに。
0 コメント:
コメントを投稿