## 2019年11月16日土曜日

### 数学 - Python - 円の中にひそむ関数 - 三角関数 - 加法定理 - 三角関数の合成 - 正弦と余弦、方程式の解

1. $\begin{array}{l}\mathrm{sin}\theta =\mathrm{cos}\theta \\ \mathrm{sin}\theta -\mathrm{cos}\theta =0\\ \sqrt{2}\left(\mathrm{sin}\theta \mathrm{cos}\frac{7}{4}\pi +\mathrm{cos}\theta \mathrm{sin}\frac{7}{4}\pi \right)=0\\ \sqrt{2}\mathrm{sin}\left(\theta +\frac{7}{4}\pi \right)=0\\ \theta +\frac{7}{4}\pi =n\pi \\ \theta =n\pi -\frac{7}{4}\pi \\ \theta =\frac{\pi }{4},\frac{5}{4}\pi \end{array}$

2. $\begin{array}{l}\mathrm{sin}\theta +\mathrm{cos}\theta =-1\\ \sqrt{2}\left(\mathrm{sin}\theta \mathrm{cos}\frac{\pi }{4}+\mathrm{cos}\theta \mathrm{sin}\frac{\pi }{4}\right)=-1\\ \sqrt{2}\mathrm{sin}\left(\theta +\frac{\pi }{4}\right)=-1\\ \mathrm{sin}\left(\theta +\frac{\pi }{4}\right)=-\frac{1}{\sqrt{2}}\\ \theta +\frac{\pi }{4}=\frac{5}{4}\pi +2n\pi ,\frac{7}{4}\pi +2m\pi \\ \theta =\pi ,\frac{3}{2}\pi \end{array}$

3. $\begin{array}{l}\mathrm{sin}\theta -\sqrt{3}\mathrm{cos}\theta =0\\ 2\left(\mathrm{sin}\theta \mathrm{cos}\frac{5}{3}\pi +\mathrm{cos}\theta \mathrm{sin}\frac{5}{3}\pi \right)=0\\ 2\mathrm{sin}\left(\theta +\frac{5}{3}\pi \right)=0\\ \theta +\frac{5}{3}\pi =n\pi \\ \theta =-\frac{5}{3}\pi +n\pi \\ \theta =\frac{1}{3}\pi ,\frac{4}{3}\pi \end{array}$

4. $\begin{array}{l}\mathrm{cos}\theta -\sqrt{3}\mathrm{sin}\theta =1\\ 2\left(\mathrm{sin}\frac{5}{6}\pi \mathrm{cos}\theta +\mathrm{cos}\frac{5}{6}\pi \mathrm{sin}\theta \right)=1\\ 2\mathrm{sin}\left(\theta +\frac{5}{6}\pi \right)=1\\ \mathrm{sin}\left(\theta +\frac{5}{6}\pi \right)=\frac{1}{2}\\ \theta +\frac{5}{6}\pi =\frac{\pi }{6}+2n\pi ,\frac{5}{6}\pi +2m\pi \\ \theta =0,\frac{4}{3}\pi \end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, sin, cos, sqrt, pi, solveset, Interval

print('21.')
theta = symbols('θ')

class MyTestCase(TestCase):
def test(self):
spam = [sin(theta) - cos(theta),
sin(theta) + cos(theta) + 1,
sin(theta) - sqrt(3) * cos(theta),
cos(theta) - sqrt(3) * sin(theta) - 1]
egg = [{pi / 4, 5 * pi / 4},
{pi, 3 * pi / 2},
{pi / 3, 4 * pi / 3},
{0, 4 * pi / 3}]
for s, t in zip(spam, egg):
self.assertEqual(
solveset(s, theta, domain=Interval.Ropen(0, 2 * pi)), t)

if __name__ == '__main__':
main()


% ./sample21.py -v
21.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 1.055s

OK
%