## 2020年7月20日月曜日

### 数学 - Python - 放物線・だ円・双曲線 - 2次関数 - 2次曲線と直線 - だ円・双曲線と直線 - 楕円と直線の共有点の個数、判別式

1. ${x}^{2}+2{\left(-x+k\right)}^{2}=4$
$3{x}^{2}-4kx+2{k}^{2}-4=0$
$\frac{D}{4}=4{k}^{2}-3\left(2{k}^{2}-4\right)$
$=-2{k}^{2}+12$
$=-2\left({k}^{2}-6\right)$

よって

$k<-\sqrt{6},\sqrt{6}

のとき 問題のだ円と直線の共有点の個数は0個。

$k=±\sqrt{6}$

のとき1個。

$-\sqrt{6}

のとき2個。

2. ${x}^{2}+2{\left(mx+2\right)}^{2}=4$
$\left(1+2{m}^{2}\right){x}^{2}+2·4mx+4=0$
$\frac{D}{4}=16{m}^{2}-\left(1+2{m}^{2}\right)·4$
$=4\left(4{m}^{2}-\left(1+2{m}^{2}\right)\right)$
$=4\left(2{m}^{2}-1\right)$

よって

$-\frac{1}{\sqrt{2}}

のとき0個。

$m=±\frac{1}{\sqrt{2}}$

のとき1個。

$m<-\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}}

のとき2個。

コード

#!/usr/bin/env python3
from sympy import plot, solve, symbols, sqrt

print('16.')

x, y = symbols('x, y', real=True)
eq = x ** 2 + 2 * y ** 2 - 4
ys = solve(eq, y)
p = plot(*ys,
*[-x + k for k in [-3, -sqrt(6), 0, sqrt(6), 3]],
*[m * x + 2 for m in [-1, -1 / sqrt(2), 0, 1 / sqrt(2), 1]],
(x, -5, 5),
ylim=(-5, 5),
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
print(o, color)
p.save('sample16.png')
p.show()


% ./sample16.py
16.
cartesian line: -sqrt(8 - 2*x**2)/2 for x over (-5.0, 5.0) red
cartesian line: sqrt(8 - 2*x**2)/2 for x over (-5.0, 5.0) green
cartesian line: -x - 3 for x over (-5.0, 5.0) blue
cartesian line: -x - sqrt(6) for x over (-5.0, 5.0) brown
cartesian line: -x for x over (-5.0, 5.0) orange
cartesian line: -x + sqrt(6) for x over (-5.0, 5.0) purple
cartesian line: 3 - x for x over (-5.0, 5.0) pink
cartesian line: 2 - x for x over (-5.0, 5.0) gray
cartesian line: -sqrt(2)*x/2 + 2 for x over (-5.0, 5.0) skyblue
cartesian line: 2 for x over (-5.0, 5.0) yellow
%