学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
解析入門 原書第3版 (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第Ⅵ部(多変数の関数)、第20章(合成微分律と勾配ベクトル)、3(方向微分係数)の練習問題4の解答を求めてみる。
よって、問題 の X の関数が与えられた点(1,-1,2)で最も急速に増加する向きは、
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, sin, cos, Rational, sqrt, pi
from sympy.plotting import plot3d
print('4.')
x, y, z, w = symbols('x, y, z, w', real=True)
class TestGrad(TestCase):
def test_a(self):
f = x / Matrix([x, y, z]).norm() ** Rational(3, 2)
self.assertEqual(
Matrix([f.diff(o, 1) for o in [x, y, z]]).subs(
{x: 1, y: -1, z: 2}),
3 * Matrix([1 / (4 * 6 ** Rational(3, 4)),
1 / (2 * 6 ** Rational(7, 4)),
-1 / 6 ** Rational(7, 4)])
)
def test_b(self):
f = Matrix([x, y, z, w]).norm() ** 5
self.assertEqual(
Matrix([f.diff(o, 1) for o in [x, y, z, w]]).subs(
{x: 1, y: 2, z: -1, w: 1}),
5 * 7 ** Rational(3, 2) * Matrix([1, 2, -1, 1])
)
for i, f in enumerate([x / Matrix([x, y, 2]).norm() ** Rational(3, 2),
Matrix([x, y, -1, 1]).norm() ** 5]):
c = chr(ord("a") + i)
p = plot3d(f,
(x, -5, 5),
(y, -5, 5),
show=False)
p.save(f'sample4_{c}.png')
p.show()
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample4.py -v
4.
test_a (__main__.TestGrad) ... ok
test_b (__main__.TestGrad) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.043s
OK
%
0 コメント:
コメントを投稿