三角関数
三角関数は指数関数とは姉妹のようなものである。
オイラーの公式より、
これらから、
z = x + iy を代入して、
sin, tanは、
これらより、
import std.cstream;
import std.math;void main(char[][] args) {
cdouble c = 1 + 0.1i;
dout.writefln(cos(c)); // 0.543006+-0.0842874i
dout.writefln(sin(c)); // 0.845682+0.0541203i
dout.writefln(tan(c)); // 1.50566+0.333382i
}cdouble cos(cdouble z) {
double x = z.re;
double y = z.im;
double e = std.math.exp(y);
double e_1 = 1 / e;
return (e + e_1) / 2 * std.math.cos(x)
- 1i * (e - e_1) / 2 * std.math.sin(x);
}cdouble sin(cdouble z) {
double x = z.re;
double y = z.im;
double e = std.math.exp(y);
double e_1 = 1 / e;
return (e + e_1) / 2 * std.math.sin(x)
+ 1i * (e - e_1) / 2 * std.math.cos(x);
}cdouble tan(cdouble z) {
double x = z.re;
double y = z.im;
double e2 = std.math.exp(y * 2);
double t = std.math.tan(x);
return (1i * (e2 - 1) + (e2 + 1) * t)
/ (e2 + 1 - 1i * (e2 - 1) * t);
}