## 2020年5月26日火曜日

### 数学 - Pytyhon - 解析学 - ベクトル - 空間の点の定義 - 2つのベクトル、演算、加法、乗法、座標、グラフ上での点

1. $\begin{array}{l}A+2B=\left(0,1\right)\\ A+3B=\left(-1,2\right)\\ A-2B=\left(4,-3\right)\\ A-3B=\left(5,-4\right)\\ A+\frac{1}{2}B=\left(\frac{3}{2},-\frac{1}{2}\right)\end{array}$

グラフ。

コード

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

print('8.')

A = Matrix([2, -1])
B = Matrix([-1, 1])
cs = [2, 3, - 2, -3, Rational(1, 2)]
CS = [A + c * B for c in cs]
DS = [Matrix([x, y])
for x, y in [(0, 1), (-1, 2), (4, -3), (5, -4),
(Rational(3, 2), -Rational(1, 2))]]

class TextVector(TestCase):
def test(self):
for C, D in zip(CS, DS):
self.assertEqual(C, D)

t = symbols('t')
p = plot_parametric(*[(t * x, t * y, (t, 0, 1))
for x, y in DS],
*[(*(A + t * (C - A)), (t, 0, 1)) for C in CS],
xlim=(-5, 5),
ylim=(-5, 5),
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('sample8.png')

if __name__ == "__main__":
main()


% ./sample8.py -v
8.
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sympy/plotting/plot.py:1065: MatplotlibDeprecationWarning:
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
self.ax[i].spines['left'].set_smart_bounds(True)
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sympy/plotting/plot.py:1066: MatplotlibDeprecationWarning:
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
self.ax[i].spines['bottom'].set_smart_bounds(False)
test (__main__.TextVector) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
%