## 2019年11月10日日曜日

### 数学 - Python - 解析学 - “ε-δ”その他 - 複素数 - 極形式 - 三角関数(正弦と余弦)、極形式

1. $\begin{array}{l}\frac{{e}^{i\theta }+{e}^{-i\theta }}{2}\\ =\frac{\mathrm{cos}\theta +i\mathrm{sin}\theta +\mathrm{cos}\left(-\theta \right)+i\mathrm{sin}\left(-\theta \right)}{2}\\ =\frac{\mathrm{cos}\theta +i\mathrm{sin}\theta +\mathrm{cos}\theta -i\mathrm{sin}\theta }{2}\\ =\mathrm{cos}\theta \\ \frac{{e}^{i\theta }-{e}^{-i\theta }}{2i}\\ =\frac{\left(\mathrm{cos}\theta +i\mathrm{sin}\theta \right)-\left(\mathrm{cos}\left(-\theta \right)+i\mathrm{sin}\left(-\theta \right)\right)}{2i}\\ =\frac{\left(\mathrm{cos}\theta +i\mathrm{sin}\theta \right)-\left(\mathrm{cos}\theta -i\mathrm{sin}\theta \right)}{2i}\\ =\mathrm{sin}\theta \end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, exp, sin, cos, I

print('9.')

theta = symbols('θ', real=True)

class MyTestCase(TestCase):
def test1(self):
self.assertEqual(cos(theta).as_real_imag(),
((exp(I * theta) + exp(-I * theta)) / 2).as_real_imag())

def test2(self):
self.assertEqual(
sin(theta).as_real_imag(), ((exp(I * theta) - exp(-I * theta)) / (2 * I)).as_real_imag())

if __name__ == '__main__':
main()


% ./sample9.py -v
9.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.013s

OK
%