学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
続 解析入門 (原書第2版) (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第2章(ベクトルの微分)、1(微分係数)の練習問題1、2、3、4の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, sin, cos, exp, log, Derivative
from sympy.abc import t
from sympy.plotting import plot3d_parametric_line
print('1, 2, 3, 4.')
class Test(TestCase):
def test1(self):
self.assertEqual(
Derivative(Matrix([exp(t), cos(t), sin(t)]), t, 1).doit(),
Matrix([exp(t), -sin(t), cos(t)])
)
def test2(self):
self.assertEqual(
Derivative(Matrix([sin(2 * t), log(1 + t), t]), t, 1).doit(),
Matrix([2 * cos(2 * t), 1 / (1 + t), 1])
)
def test3(self):
self.assertEqual(
Derivative(Matrix([cos(t), sin(t)]), t, 1).doit(),
Matrix([-sin(t), cos(t)])
)
def test4(self):
self.assertEqual(
Derivative(Matrix([cos(3 * t), sin(3 * t)]), t, 1).doit(),
Matrix([-3 * sin(3 * t), 3 * cos(3 * t)])
)
p = plot3d_parametric_line(
(exp(t), cos(t), sin(t), (t, -5, 5)),
*[(exp(t0) + t * exp(t0),
cos(t0) - t * sin(t0),
sin(t0) + t * cos(t0),
(t, 0, 1))
for t0 in range(-5, 6) if t0 != 0],
legend=False,
show=False
)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
for o, color in zip(p, colors):
o.line_color = color
p.save('sample1.png')
p.show()
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample1.py -v
1, 2, 3, 4.
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok
test3 (__main__.Test) ... ok
test4 (__main__.Test) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.013s
OK
%
0 コメント:
コメントを投稿