## 2020年3月4日水曜日

### 数学 - Python - 線形代数学 - 線形写像 - 写像 - 指数関数、パラメーター曲線、写像の和

ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の4章(線形写像)、1(写像)、練習問題5の解答を求めてみる。

• $\begin{array}{l}\left(F+G\right)\left(1\right)\\ =F\left(1\right)+G\left(1\right)\\ =\left(e,1\right)+\left(1,2\right)\\ =\left(e+1,3\right)\end{array}$

• $\begin{array}{l}\left(F+G\right)\left(2\right)\\ =\left({e}^{2},2\right)+\left(2,4\right)\\ =\left({e}^{2}+2,6\right)\end{array}$

• $\begin{array}{l}\left(F+G\right)\left(0\right)\\ =\left(1,0\right)+\left(0,0\right)\\ =\left(1,0\right)\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, exp, symbols
from sympy.plotting import plot_parametric

print('5.')

t = symbols('t')
f = Matrix([exp(t), t])
g = Matrix([t, 2 * t])

class MyTestCase(TestCase):
def test(self):
ts = [1, 2, 0]
bs = [(exp(1) + 1, 3),
(exp(2) + 2, 6),
(1, 0)]
for t0, b in zip(ts, bs):
self.assertEqual((f + g).subs({t: t0}), Matrix(b))

p = plot_parametric(*[(*h, (t, -1, 4)) for h in [f, g, f + g]],
legend=True, 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.show()
p.save('sample5.png')

if __name__ == '__main__':
main()


% ./sample5.py -v
5.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.003s

OK
%