2020年3月8日日曜日

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

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

よって、 正弦の実部と虚部は、

$\begin{array}{l}\mathrm{Re}\left(\mathrm{sin}z\right)=\mathrm{sin}x\frac{{e}^{y}+{e}^{-y}}{z}\\ \mathrm{Im}\left(\mathrm{sin}z\right)=\mathrm{cos}x\frac{{e}^{y}-{e}^{-y}}{2}\end{array}$

余弦について、

$\begin{array}{l}\mathrm{cos}z\\ =\mathrm{cos}\left(x+yi\right)\\ =\mathrm{cos}x\mathrm{cos}yi-\mathrm{sin}x\mathrm{sin}yi\\ =\mathrm{cos}x\frac{{e}^{-y}+{e}^{y}}{2}-\mathrm{sin}x\frac{{e}^{-y}-{e}^{y}}{2i}\\ =\mathrm{cos}x\frac{{e}^{y}+{e}^{-y}}{2}-i\mathrm{sin}x\frac{{e}^{y}-{e}^{-y}}{2}\\ \mathrm{Re}\left(\mathrm{cos}z\right)=\mathrm{cos}x\frac{{e}^{y}+{e}^{-y}}{2}\\ \mathrm{Im}\left(\mathrm{cos}z\right)=-\mathrm{sin}x\frac{{e}^{y}-{e}^{-y}}{2}\end{array}$

コード

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

print('5.')

x, y = symbols('x, y', real=True)
z = x + y * I

class MyTestCase(TestCase):
def test_sine(self):
r, i = sin(z).as_real_imag()
self.assertEqual(r, (sin(x) * (exp(y) + exp(-y)) / 2).simplify())
self.assertEqual(i, (cos(x) * (exp(y) - exp(-y)) / 2).simplify())

def test_cosine(self):
r, i = cos(z).as_real_imag()
self.assertEqual(r, (cos(x) * (exp(y) + exp(-y)) / 2).simplify())
self.assertEqual(i, (-sin(x) * (exp(y) - exp(-y)) / 2).simplify())

if __name__ == "__main__":
main()


% ./sample5.py -v
5.
test_cosine (__main__.MyTestCase) ... ok
test_sine (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.460s

OK
%