学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
解析入門 原書第3版 (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第Ⅵ部(多変数の関数)、第17章(ベクトル)、4(ベクトルのノルム)の練習問題3の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, pi, Rational
print('3.')
def eq(A, B):
for a, b in zip(A, B):
if a.simplify() != b.simplify():
return False
return True
class MyTestCase(TestCase):
def test(self):
As = [(2, -1),
(-1, 3),
(2, -1, 5),
(-1, -2, 3),
(pi, 3, -1),
(15, -2, 4)]
Bs = [(-1, 1),
(0, 4),
(-1, 1, 1),
(-1, 3, -4),
(2 * pi, -3, 7),
(pi, 3, -1)]
egg = [(Rational(3, 2), -Rational(3, 2)),
(0, 3),
(-Rational(2, 3), Rational(2, 3), Rational(2, 3)),
(Rational(17, 26), -Rational(51, 26), Rational(34, 13)),
((2 * pi ** 3 - 16 * pi) / (2 * pi ** 2 + 29), (-3 * pi ** 2 + 24) /
(2 * pi ** 2 + 29), (7 * pi ** 2 - 56) / (2 * pi ** 2 + 29)),
((15 * pi ** 2 - 10 * pi) / (pi ** 2 + 10), (45 * pi - 30) /
(pi ** 2 + 10), (-15 * pi + 10) / (pi ** 2 + 10))]
for A, B, C in zip(As, Bs, egg):
A = Matrix(A)
B = Matrix(B)
C = Matrix(C)
self.assertTrue(eq(A.dot(B) / B.dot(B) * B, C))
if __name__ == '__main__':
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample3.py -v
3.
test (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.878s
OK
%
0 コメント:
コメントを投稿