学習環境
- Surface 3 (4G LTE)、Surface 3 タイプ カバー、Surface ペン(端末)
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad Pro + Apple Pencil
- MyScript Nebo(iPad アプリ)
- 参考書籍
解析入門〈3〉(松坂 和夫(著)、岩波書店)の第14章(多変数の関数)、14.1(微分可能性と勾配ベクトル)、問題11.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
from sympy import pprint, symbols, log, sqrt, Matrix, Derivative
x, y, z = symbols('x, y, z')
xs = [x, y, z]
f = x ** 2 * y
g = log(sqrt(x ** 2 + y ** 2 + z ** 2))
h = (x + y) ** 2 + (y + z) ** 2 + (z + x) ** 2
fs = [(f, 2), (g, 3), (h, 3)]
gradfs = [Matrix([Derivative(f0, xi, 1).doit() for xi in xs][:i])
for f0, i in fs]
points = [((2, -1), (1, 1)),
((-1, 1, 2), (1, 2, 2)),
((2, 2, - 1), (5, 5, 2))]
for i, ((f, _), gradf, (p1, p2)) in enumerate(zip(fs, gradfs, points)):
print(f'({chr(ord("a") + i)})')
p1 = Matrix(p1)
p2 = Matrix(p2) / Matrix(p2).norm()
for t in [f, gradf.T, p1.T, p2.T, gradf.subs(dict(zip(xs, p1))).dot(p2)]:
pprint(t)
print()
print()
入出力結果(Terminal, Jupyter(IPython))
$ ./sample11.py
(a)
2
x ⋅y
⎡ 2⎤
⎣2⋅x⋅y x ⎦
[2 -1]
⎡√2 √2⎤
⎢── ──⎥
⎣2 2 ⎦
0
(b)
⎛ ______________⎞
⎜ ╱ 2 2 2 ⎟
log⎝╲╱ x + y + z ⎠
⎡ x y z ⎤
⎢──────────── ──────────── ────────────⎥
⎢ 2 2 2 2 2 2 2 2 2⎥
⎣x + y + z x + y + z x + y + z ⎦
[-1 1 2]
[1/3 2/3 2/3]
5/18
(c)
2 2 2
(x + y) + (x + z) + (y + z)
[4⋅x + 2⋅y + 2⋅z 2⋅x + 4⋅y + 2⋅z 2⋅x + 2⋅y + 4⋅z]
[2 2 -1]
⎡5⋅√6 5⋅√6 √6⎤
⎢──── ──── ──⎥
⎣ 18 18 9 ⎦
6⋅√6
$
0 コメント:
コメントを投稿