10 inline void evaluate_eigenValues(
double ell, X& lambda, X& freq)
14 for (
unsigned int i = 0; i < lambda.size(); i++)
16 lambda[i] = 2.0 * c /(freq[i] * freq[i] + c * c);
21 double res(
double x,
double ell)
24 double g = std::tan(x) - 2.0 * c * x / (x * x - c * c);
29 double findRoot(
double ell,
double a,
double b)
32 double fa, fb, x, fx, error, m;
39 m = (fb - fa) / (b - a);
42 if (((fa < 0) & (fx < 0)) | ((fa > 0) & (fx > 0))) { a = x; }
47 std::cout <<
"Warning: root finder hasn't converged. Check number of KL modes and correlation length." << std::endl;
55 void rootFinder(
int M,
double ell, std::vector<double>& answer)
58 std::vector<double> freq(M+2);
64 for (
int i = 0; i < M+1; i++)
69 double w_min = (i - 0.4999) * M_PI;
70 double w_max = (i + 0.4999) * M_PI;
74 if ((w_min <= c) && (w_max >= c))
81 freq[m] = findRoot(ell,w_min,0.5*(c+w_min));
85 freq[m] = findRoot(ell,0.5*(c + w_max),w_max);
90 freq[m] = findRoot(ell,w_min,w_max);
95 for (
int i = 0; i < M; i++)
97 answer[i] = freq[i+1];