学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
解析入門 原書第3版 (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第Ⅵ部(多変数の関数)、第18章(ベクトルの微分)、1(微分係数)の練習問題1、2、3、4の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, exp, sin, cos, symbols, Derivative, log
from sympy.plotting import plot_parametric, plot3d_parametric_line
print('1, 2, 3, 4.')
t = symbols('t')
class MyTestCase(TestCase):
def test1(self):
x = Matrix([exp(t), cos(t), sin(t)])
self.assertEqual(Derivative(x, t, 1).doit(),
Matrix([exp(t), -sin(t), cos(t)]))
def test2(self):
x = Matrix([sin(2 * t), log(1 + t), t])
self.assertEqual(Derivative(x, t, 1).doit(),
Matrix([2 * cos(2 * t), 1 / (1 + t), 1]))
def test3(self):
x = Matrix([cos(t), sin(t)])
self.assertEqual(Derivative(x, t, 1).doit(),
Matrix([-sin(t), cos(t)]))
def test4(self):
x = Matrix([cos(3 * t), sin(3 * t)])
self.assertEqual(Derivative(x, t, 1).doit(),
Matrix([-3 * sin(3 * t), 3 * cos(3 * t)]))
p1 = plot3d_parametric_line(exp(t), cos(t), sin(t), show=False, legend=True)
p1.save('sample1_1.png')
p2 = plot3d_parametric_line(sin(2 * t), log(1 + t),
t, (t, -0.9, 10), show=False, legend=True)
p2.save('sample1_2.png')
p3 = plot_parametric(cos(t), sin(t), legend=True, show=False)
p3.save('sample1_3.png')
p4 = plot_parametric(cos(3 * t), sin(3 * t), legend=True, show=False)
p4.save('sample1_4.png')
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample1.py -v
1, 2, 3, 4.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok
test4 (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.013s
OK
%
0 コメント:
コメントを投稿