Theoretica
A C++ numerical and automatic mathematical library
complex_analysis.h
Go to the documentation of this file.
1 
5 
6 #ifndef THEORETICA_COMPLEX_FUNCTIONS
7 #define THEORETICA_COMPLEX_FUNCTIONS
8 
9 #include "./complex.h"
10 #include "../core/real_analysis.h"
11 
12 
13 namespace theoretica {
14 
15 
18  template<typename T>
20  return z;
21  }
22 
23 
26  template<typename T>
28  return complex<T>(z.a, -z.b);
29  }
30 
31 
34  template<typename T>
36  return conjugate(z) / z.sqr_norm();
37  }
38 
39 
42  template<typename T>
44  return complex<T>(
45  square(z.Re()) - square(z.Im()),
46  2 * z.Re() * z.Im());
47  }
48 
49 
52  template<typename T>
54  return complex<T>(
55  cube(z.Re()) - 3 * z.Re() * square(z.Im()),
56  3 * square(z.Re()) * z.Im() - cube(z.Im()));
57  }
58 
59 
62  template<typename T>
64  return complex<T>(cos(z.Im()), sin(z.Im())) * exp(z.Re());
65  }
66 
67 
70  template<typename T>
71  inline real abs(complex<T> z) {
72  return z.norm();
73  }
74 
75 
78  template<typename T>
80 
81  const complex<T> t = z * complex<T>(0, 1);
82  return (exp(t) - exp(-t)) / complex<T>(0, 2);
83  }
84 
85 
88  template<typename T>
90 
91  const complex<T> t = z * complex<T>(0, 1);
92  return (exp(t) + exp(-t)) / 2.0;
93  }
94 
95 
98  template<typename T>
100 
101  const complex<T> t = z * complex<T>(0, 2);
102  return (exp(t) - 1) / (exp(t) + 1) * complex<T>(0, -1);
103  }
104 
105 
108  template<typename T>
110 
111  if(abs(z.a) < MACH_EPSILON && abs(z.b) < MACH_EPSILON)
112  return complex<T>(0);
113 
114  return complex<T>(
115  INVSQR2 * sqrt((z.norm() + z.Re())),
116  INVSQR2 * sqrt((z.norm() - z.Re())) * sgn(z.b));
117  }
118 
119 
122  template<typename T>
124  return complex<T>(ln(z.norm()), z.arg());
125  }
126 
127 
130  template<typename T>
132  return ln(complex<T>(0, 1) * z + sqrt(complex<T>(1, 0) - square(z))) * complex<T>(0, -1);
133  }
134 
135 
138  template<typename T>
140  return ln(z + sqrt(square(z) - 1)) * complex<T>(0, -1);
141  }
142 
143 
146  template<typename T>
148  return ln((complex<T>(0, 1) - z) / (complex<T>(0, 1) + z)) * complex<T>(0, -0.5);
149  }
150 
151 
152 }
153 
154 #endif
Complex number in algebraic form .
Definition: complex.h:26
Type a
Real part.
Definition: complex.h:30
Type sqr_norm() const
Compute the square norm of the complex number.
Definition: complex.h:128
Type Re() const
Get the real part of the complex number.
Definition: complex.h:74
Type b
Imaginary part.
Definition: complex.h:33
Type arg() const
Get the argument of the complex number.
Definition: complex.h:173
Type norm() const
Compute the norm of the complex number.
Definition: complex.h:134
Type Im() const
Get the imaginary part of the complex number.
Definition: complex.h:98
Complex number class.
Main namespace of the library which contains all functions and objects.
Definition: algebra.h:27
double real
A real number, defined as a floating point type.
Definition: constants.h:188
dual2 sqrt(dual2 x)
Compute the square root of a second order dual number.
Definition: dual2_functions.h:54
dual2 ln(dual2 x)
Compute the natural logarithm of a second order dual number.
Definition: dual2_functions.h:139
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition: dual2_functions.h:183
dual2 asin(dual2 x)
Compute the arcsine of a second order dual number.
Definition: dual2_functions.h:189
dual2 exp(dual2 x)
Compute the exponential of a second order dual number.
Definition: dual2_functions.h:130
constexpr real INVSQR2
The inverse of the square root of 2.
Definition: constants.h:254
complex< T > inverse(complex< T > z)
Compute the conjugate of a complex number.
Definition: complex_analysis.h:35
dual2 conjugate(dual2 x)
Return the conjugate of a second order dual number.
Definition: dual2_functions.h:35
dual2 cos(dual2 x)
Compute the cosine of a second order dual number.
Definition: dual2_functions.h:82
constexpr real MACH_EPSILON
Machine epsilon for the real type.
Definition: constants.h:197
dual2 tan(dual2 x)
Compute the tangent of a second order dual number.
Definition: dual2_functions.h:94
dual2 acos(dual2 x)
Compute the arcosine of a second order dual number.
Definition: dual2_functions.h:206
int sgn(real x)
Return the sign of x (1 if positive, -1 if negative, 0 if null)
Definition: real_analysis.h:259
dual2 sin(dual2 x)
Compute the sine of a second order dual number.
Definition: dual2_functions.h:70
complex< T > identity(complex< T > z)
Complex identity.
Definition: complex_analysis.h:19
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition: dual2_functions.h:23
dual2 atan(dual2 x)
Compute the arctangent of a second order dual number.
Definition: dual2_functions.h:223
dual2 cube(dual2 x)
Return the cube of a second order dual number.
Definition: dual2_functions.h:29