学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
続 解析入門 (原書第2版) (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第1章(ベクトル)、4(ベクトルのノルム)の練習問題8の解答を求めてみる。
(証明終)
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix
print('8.')
class Test(TestCase):
def test(self):
a = Matrix(symbols('a:10', real=True))
b = Matrix(symbols('b:10', real=True))
for i, (s, t) in enumerate([
((a + b).norm() ** 2 + (a - b).norm() ** 2,
2 * a.norm() ** 2 + 2 * b.norm() ** 2),
((a + b).norm() ** 2,
a.norm() ** 2 + b.norm() ** 2 + 2 * a.dot(b)),
((a + b).norm() ** 2 - (a - b).norm() ** 2,
4 * a.dot(b))
]):
print(f'({chr(ord("a") + i)})')
self.assertEqual(s.expand(), t.expand())
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample8.py -v
8.
test (__main__.Test) ... (a)
(b)
(c)
ok
----------------------------------------------------------------------
Ran 1 test in 0.119s
OK
%
0 コメント:
コメントを投稿