2019-08-23 11:16:46 +03:00
|
|
|
#include <qpms/beyn.h>
|
|
|
|
#include <stdio.h>
|
2019-09-02 11:57:25 +03:00
|
|
|
#include <string.h>
|
2019-08-23 11:16:46 +03:00
|
|
|
|
|
|
|
// Matrix as in Beyn, section 4.11
|
2019-09-02 11:57:25 +03:00
|
|
|
int M_function(complex double *target, const size_t m, const complex double z, void *no_params) {
|
|
|
|
complex double d = 2*m - 4*z / (6*m);
|
|
|
|
complex double od = -((double)m) - z / (6*m);
|
2019-08-23 11:16:46 +03:00
|
|
|
|
2019-09-02 11:57:25 +03:00
|
|
|
memset(target, 0, m*m*sizeof(complex double));
|
2019-08-23 11:16:46 +03:00
|
|
|
for (int i = 0; i < m; ++i) {
|
2019-09-02 11:57:25 +03:00
|
|
|
target[i*m + i] = d;
|
|
|
|
if(i > 0) target[i*m + i-1] = od;
|
|
|
|
if(i < m - 1) target[i*m + i+1] = od;
|
2019-08-23 11:16:46 +03:00
|
|
|
}
|
2019-09-02 11:57:25 +03:00
|
|
|
target[m*(m-1) + m-1] = d/2 + z/(z-1);
|
2019-08-23 11:16:46 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
complex double z0 = 150+2*I;
|
|
|
|
double Rx = 148, Ry = 148;
|
|
|
|
int L = 10, N = 50, dim = 400;
|
2019-08-29 17:18:59 +03:00
|
|
|
beyn_contour_t *contour = beyn_contour_ellipse(z0, Rx, Ry, N);
|
2019-08-23 11:16:46 +03:00
|
|
|
|
2019-09-02 11:57:25 +03:00
|
|
|
beyn_result_t *result;
|
|
|
|
int K = beyn_solve(&result, dim, L, M_function, NULL /*M_inv_Vhat_function*/, NULL /*params*/,
|
2019-08-29 17:18:59 +03:00
|
|
|
contour, 1e-4, 0);
|
2019-08-23 11:16:46 +03:00
|
|
|
printf("Found %d eigenvalues:\n", K);
|
|
|
|
for (int i = 0; i < K; ++i) {
|
2019-09-02 11:57:25 +03:00
|
|
|
complex double eig = result->eigval[i];
|
|
|
|
printf("%d: %g%+gj\n", i, creal(eig), cimag(eig));
|
2019-08-23 11:16:46 +03:00
|
|
|
}
|
2019-08-29 17:18:59 +03:00
|
|
|
free(contour);
|
2019-09-02 11:57:25 +03:00
|
|
|
beyn_result_free(result);
|
2019-08-23 11:16:46 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|