## 2020年3月7日土曜日

### 数学 - Python - 解析学 - 関数列と関数級数 - 複素整級数(指数関数・三角関数再論) - 三角関数の加法定理(正弦と余弦)

• $\begin{array}{l}\mathrm{sin}z\mathrm{cos}w+\mathrm{cos}z\mathrm{sin}w\\ =\frac{{e}^{iz}-{e}^{-iz}}{2i}·\frac{{e}^{iw}+{e}^{-iw}}{2}+\frac{{e}^{iz}+{e}^{-iz}}{2}·\frac{{e}^{iw}-{e}^{-iw}}{2i}\\ =\frac{1}{4i}\left({e}^{i\left(z+w\right)}+{e}^{i\left(z-w\right)}-{e}^{i\left(-z+w\right)}-{e}^{i\left(-z-w\right)}+{e}^{i\left(z+w\right)}-{e}^{i\left(z-w\right)}+{e}^{i\left(-z+w\right)}-{e}^{i\left(-z-w\right)}\right)\\ =\frac{1}{4i}\left(2{e}^{i\left(z+w\right)}-2{e}^{-i\left(z+w\right)}\right)\\ =\frac{{e}^{i\left(z+w\right)}-{e}^{-i\left(z+w\right)}}{2i}\\ =\mathrm{sin}\left(z+w\right)\end{array}$

• $\begin{array}{l}\mathrm{cos}z\mathrm{cos}w-\mathrm{sin}z\mathrm{sin}w\\ =\frac{{e}^{iz}+{e}^{-iz}}{2}·\frac{{e}^{iw}+{e}^{-iw}}{2}-\frac{{e}^{iz}-{e}^{-iz}}{2i}·\frac{{e}^{iw}-{e}^{-iw}}{2i}\\ =\frac{{e}^{i\left(z+w\right)}+{e}^{i\left(z-w\right)}+{e}^{i\left(-z+w\right)}+{e}^{-i\left(z+w\right)}}{4}\\ +\frac{{e}^{i\left(z+w\right)}-{e}^{i\left(z-w\right)}-{e}^{i\left(-z+w\right)}+{e}^{-i\left(z+w\right)}}{4}\\ =\frac{2{e}^{i\left(z+w\right)}+2{e}^{-i\left(z+w\right)}}{4}\\ =\frac{{e}^{i\left(z+w\right)}+{e}^{-i\left(z+w\right)}}{z}\\ =\mathrm{cos}\left(z+w\right)\end{array}$

コード

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

print('4.')

z, w = symbols('z, w', imag=True)

class MyTestCase(TestCase):
def test_sine(self):
a, b = sin(z + w).as_real_imag()
c, d = (sin(z) * cos(w) + cos(z) * sin(w)).as_real_imag()
self.assertEqual(a.simplify(), c.simplify())
self.assertEqual(b.simplify(), d.simplify())

def test_cosine(self):
a, b = cos(z + w).as_real_imag()
c, d = (cos(z) * cos(w) - sin(z) * sin(w)).as_real_imag()
self.assertEqual(a.simplify(), c.simplify())
self.assertEqual(b.simplify(), d.simplify())

if __name__ == "__main__":
main()


% ./sample4.py -v
4.
test_cosine (__main__.MyTestCase) ... ok
test_sine (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 1.312s

OK
%