学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
続 解析入門 (原書第2版) (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第2章(ベクトルの微分)、1(微分係数)の練習問題18の解答を求めてみる。
よって、 2曲線は
で交わる。
よって、接線の間の角の余弦は
よって、求める角は
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, Derivative, exp, symbols, sin, cos, solve
from sympy.plotting import plot3d_parametric_line
print('18.')
t, theta = symbols('t, θ', real=True)
x1 = Matrix([exp(t), exp(2 * t), 1 - exp(-t)])
x2 = Matrix([1 - theta, cos(theta), sin(theta)])
x11 = Derivative(x1, t, 1).doit()
x21 = Derivative(x2, theta, 1).doit()
t0 = 0
theta0 = solve((x1 - x2).subs({t: t0}), theta)[0][0]
class Test(TestCase):
def test1(self):
self.assertEqual(x1.subs({t: t0}), x2.subs({theta: theta0}))
def test2(self):
a = x11.subs({t: t0})
b = x21.subs({theta: theta0})
self.assertEqual(a.dot(b) / (a.norm() * b.norm()), 0)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
p = plot3d_parametric_line(
(*x1, (t, -1, 1)),
(*x2.subs({theta: t}), (t, -1, 1)),
(*(x1.subs({t: t0}) + t * x11.subs({t: t0})), (t, 0, 1)),
(*(x2.subs({theta: theta0}) + t * x21.subs({theta: theta0})), (t, 0, 1)),
show=False,
legend=False,
)
for o, color in zip(p, colors):
o.line_color = color
p.save(f'sample18.png')
p.show()
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample18.py -v
18.
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/ma/core.py:2831: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
_data = np.array(data, dtype=dtype, copy=copy,
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.003s
OK
%
0 コメント:
コメントを投稿