学習環境
- Surface 3 (4G LTE)、Surface 3 タイプ カバー、Surface ペン(端末)
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad Pro + Apple Pencil
- MyScript Nebo(iPad アプリ)
- 参考書籍
解析入門〈3〉(松坂 和夫(著)、岩波書店)の第13章(連続写像の空間)、13.1(ノルム空間)、問題1.を取り組んでみる。
-
-
よって、
となるので、
-
よって、
となるので、
-
コード(Emacs)
Python 3
#!/usr/bin/env python3 from sympy import pprint, symbols, Matrix, solve import random x1, y1, x2, y2, x3, y3 = symbols('x1, y1, x2, y2, x3. y3', real=True) v1 = Matrix([x1, y1]) v2 = Matrix([x2, y2]) vs = [v1, v2] def norm1(v): return sum([abs(x) for x in v]) def norm2(v): return max([abs(x) for x in v]) norms = [norm1, norm2] print('N1') for norm in norms: try: print(all([norm(v) >= 0 for v in vs])) except Exception as err: print(type(err), err) for norm in norms: for _ in range(5): x_sign = -1 if random.randrange(2) == 0 else 1 y_sign = -1 if random.randrange(2) == 0 else 1 v = Matrix([x_sign * random.random() * 10, y_sign * random.random() * 10]) pprint(v) pprint(norm(v) >= 0) print() print('N2') for norm in norms: try: pprint(solve(norm(v1), (x1, y1))) except Exception as err: print(type(err), err) print() for v in [(1, 2), (0, 0)]: pprint(v) pprint(norm(v)) print() print('N3') c = symbols('c', real=True) for norm in norms: try: l = norm(c * v1) r = abs(c) * norm(v1) for t in [l, r, l == r, l.expand() == r.expand(), l.factor() == r.factor()]: pprint(t) print() except Exception as err: print(type(err), err) print() for _ in range(5): try: x_sign = -1 if random.randrange(2) == 0 else 1 y_sign = -1 if random.randrange(2) == 0 else 1 v = Matrix([x_sign * random.random() * 10, y_sign * random.random() * 10]) l = norm(c * v) r = abs(c) * norm(v) for t in [l == r, l.expand() == r.expand(), l.factor() == r.factor()]: pprint(t) print() except Exception as err: print(type(err), err) print() print('N4') for nrom in norms: try: l = norm(v1 + v2) r = norm(v1) + norm(v2) for t in [l, r, l <= r]: pprint(t) print() except Exception as err: print(type(err), err) print() for _ in range(5): try: x_sign1 = -1 if random.randrange(2) == 0 else 1 y_sign1 = -1 if random.randrange(2) == 0 else 1 v1 = Matrix([x_sign1 * random.random() * 10, y_sign1 * random.random() * 10]) x_sign2 = -1 if random.randrange(2) == 0 else 1 y_sign2 = -1 if random.randrange(2) == 0 else 1 v2 = Matrix([x_sign2 * random.random() * 10, y_sign2 * random.random() * 10]) l = norm(v1 + v2) r = norm(v1) + norm(v2) for t in [l, r, l <= r]: pprint(t) print() except Exception as err: print(type(err), err) print()
入出力結果(Terminal, Jupyter(IPython))
$ ./sample1.py N1 True <class 'TypeError'> cannot determine truth value of Relational ⎡-3.60926710185543⎤ ⎢ ⎥ ⎣ 6.9103922185622 ⎦ True ⎡9.57041752277116 ⎤ ⎢ ⎥ ⎣-3.93028851221304⎦ True ⎡ -7.3944192349977 ⎤ ⎢ ⎥ ⎣-0.519473049306546⎦ True ⎡2.38880070572094 ⎤ ⎢ ⎥ ⎣-2.03845287170201⎦ True ⎡3.18762488061502⎤ ⎢ ⎥ ⎣-7.1638944314745⎦ True ⎡-6.41195251111337⎤ ⎢ ⎥ ⎣6.05993189592312 ⎦ True ⎡-4.81710291929288⎤ ⎢ ⎥ ⎣-5.7781933238635 ⎦ True ⎡ 5.44499970421381 ⎤ ⎢ ⎥ ⎣-0.417472228032932⎦ True ⎡8.07251073111729⎤ ⎢ ⎥ ⎣1.75368978188321⎦ True ⎡3.44930546015265⎤ ⎢ ⎥ ⎣7.61472240043842⎦ True N2 [] (1, 2) 3 (0, 0) 0 <class 'TypeError'> cannot determine truth value of Relational (1, 2) 2 (0, 0) 0 N3 │c⋅x₁│ + │c⋅y₁│ (│x₁│ + │y₁│)⋅│c│ False False False True True True True True True True True True True True True True True True <class 'TypeError'> cannot determine truth value of Relational <class 'TypeError'> cannot determine truth value of Relational <class 'TypeError'> cannot determine truth value of Relational True True True True True True <class 'TypeError'> cannot determine truth value of Relational N4 <class 'TypeError'> cannot determine truth value of Relational 14.9446119735654 14.9446119735654 True 17.6787683440230 17.6787683440230 True 12.2781313630320 14.4589230209315 True 14.7469415782085 16.8060896219550 True 6.56786992942470 7.58325266844975 True 6.56786992942470 7.58325266844975 True 7.82660756381296 18.2036912534447 True 7.41865867526981 18.1336184290229 True 9.15529273451527 11.6690643681854 True 5.96971885258877 11.1937075726179 True 18.5451943221697 18.5451943221697 True $
0 コメント:
コメントを投稿