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