## 2020年2月10日月曜日

### 数学 - Python - 解析学 - 多変数の関数 - ベクトル - 直線と平面 - 2点を等分する点、座標、直線、パラメーター方程式

1. $\left(-\frac{3}{2},4,\frac{1}{2}\right)$

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

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

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

コード

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

print('21.')

p = Matrix([1, 3, -1])
q = Matrix([-4, 5, 2])
pq = q - p

class MyTestCase(TestCase):
def test_a(self):
self.assertEqual(
(p + q) / 2, Matrix([-Rational(3, 2), 4, Rational(1, 2)]))

def test_b(self):
self.assertEqual(
p + pq / 3, Matrix([-Rational(2, 3), Rational(11, 3), 0]))
self.assertEqual(
p + 2 * pq / 3, Matrix([-Rational(7, 3), Rational(13, 3), 1]))

def test_c(self):
self.assertEqual(
p + pq / 5, Matrix([0, Rational(17, 5), -Rational(2, 5)]))

def test_d(self):
self.assertEqual(
p + 2 * pq / 5, Matrix([-1, Rational(19, 5), Rational(1, 5)]))

t = symbols('t')

p0 = plot3d_parametric_line(*(p + t * pq), legend=True, show=False)

colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

for s, color in zip(p0, colors):
s.line_color = color

p0.show()
p0.save('sample21.png')

if __name__ == "__main__":
main()


% ./sample21.py -v
21.
test_a (__main__.MyTestCase) ... ok
test_b (__main__.MyTestCase) ... ok
test_c (__main__.MyTestCase) ... ok
test_d (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.002s

OK
%