36 vec
sqr(
const cvec &data)
38 vec temp(data.length());
39 for (
int i = 0; i < data.length(); i++)
40 temp(i) =
sqr(data(i));
44 mat
sqr(
const cmat &data)
46 mat temp(data.rows(), data.cols());
47 for (
int i = 0; i < temp.rows(); i++) {
48 for (
int j = 0; j < temp.cols(); j++) {
49 temp(i, j) =
sqr(data(i, j));
55 vec
abs(
const cvec &data)
57 vec temp(data.length());
59 for (
int i = 0;i < data.length();i++)
65 mat
abs(
const cmat &data)
67 mat temp(data.rows(), data.cols());
69 for (
int i = 0;i < temp.rows();i++) {
70 for (
int j = 0;j < temp.cols();j++) {
79 double gamma(
double x) {
return tgamma(x); }
80 vec
gamma(
const vec &x) {
return apply_function<double>(tgamma, x); }
81 mat
gamma(
const mat &x) {
return apply_function<double>(tgamma, x); }
86 it_error_if(index > 170,
"fact(int index): Function overflows if index > 170.");
87 it_error_if(index < 0,
"fact(int index): index must be non-negative integer");
89 for (
int i = 1; i <= index; i++)
90 prod *= static_cast<double>(i);
97 it_assert(k <= n,
"binom(n, k): k can not be larger than n");
98 it_assert((n >= 0) && (k >= 0),
"binom(n, k): n and k must be non-negative integers");
99 k = ((n - k) < k) ? n - k : k;
102 for (
int i = 1; i <= k; ++i) {
112 it_assert(k <= n,
"binom_i(n, k): k can not be larger than n");
113 it_assert((n >= 0) && (k >= 0),
"binom_i(n, k): n and k must be non-negative integers");
114 k = ((n - k) < k) ? n - k : k;
117 for (
int i = 1; i <= k; ++i) {
127 it_assert(k <= n,
"log_binom(n, k): k can not be larger than n");
128 it_assert((n >= 0) && (k >= 0),
"log_binom(n, k): n and k must be non-negative integers");
129 k = ((n - k) < k) ? n - k : k;
132 for (
int i = 1; i <= k; i++)
133 out +=
log10(static_cast<double>(i + n - k))
134 -
log10(static_cast<double>(i));
142 it_assert((a >= 0) && (b >= 0),
"gcd(a, b): a and b must be non-negative integers");
159 vec temp(data.length());
161 for (
int i = 0;i < data.length();i++)
162 temp[i] = data[i].
real();
169 mat temp(data.rows(), data.cols());
171 for (
int i = 0;i < temp.rows();i++) {
172 for (
int j = 0;j < temp.cols();j++) {
173 temp(i, j) = data(i, j).real();
182 vec temp(data.length());
184 for (
int i = 0;i < data.length();i++)
185 temp[i] = data[i].
imag();
191 mat temp(data.rows(), data.cols());
193 for (
int i = 0;i < temp.rows();i++) {
194 for (
int j = 0;j < temp.cols();j++) {
195 temp(i, j) = data(i, j).imag();
204 vec temp(data.length());
206 for (
int i = 0;i < data.length();i++)
214 mat temp(data.rows(), data.cols());
216 for (
int i = 0;i < temp.rows();i++) {
217 for (
int j = 0;j < temp.cols();j++) {
226 cvec
conj(
const cvec &x)
230 for (
int i = 0; i < x.size(); i++) {
237 cmat
conj(
const cmat &x)
239 cmat temp(x.rows(), x.cols());
241 for (
int i = 0; i < x.rows(); i++) {
242 for (
int j = 0; j < x.cols(); j++) {
#define it_error_if(t, s)
Abort if t is true.
double binom(int n, int k)
Compute the binomial coefficient "n over k".
double gamma(double x)
Deprecated gamma function - please use tgamma() instead.
mat abs(const cmat &data)
Absolute value.
vec imag(const cvec &data)
Imaginary part of complex values.
vec arg(const cvec &data)
Argument (angle)
mat arg(const cmat &data)
Argument (angle)
vec log10(const vec &x)
log-10 of the elements
cvec conj(const cvec &x)
Conjugate of complex value.
int binom_i(int n, int k)
Compute the binomial coefficient "n over k".
#define it_assert(t, s)
Abort if t is not true.
T prod(const Vec< T > &v)
The product of all elements in the vector.
IT++ compatibility types and functions.
vec sqr(const cvec &data)
Absolute square of elements.
double log_binom(int n, int k)
Compute the base 10 logarithm of the binomial coefficient "n over k".
bin abs(const bin &inbin)
absolute value of bin
int gcd(int a, int b)
Compute the greatest common divisor (GCD) g of the elements a and b.
Elementary mathematical functions - header file.
vec real(const cvec &data)
Real part of complex values.
double fact(int index)
Calculates factorial coefficient for index <= 170.