Square lattice example mode plot
[qpms.git] / tests / tbeyn.c
blob2cef25bdefab3968b0e8738955e21ecec9beda4f
1 #include <qpms/beyn.h>
2 #include <stdio.h>
3 #include <string.h>
5 // Matrix as in Beyn, section 4.11
6 int M_function(complex double *target, const size_t m, const complex double z, void *no_params) {
7 complex double d = 2*m - 4*z / (6*m);
8 complex double od = -((double)m) - z / (6*m);
10 memset(target, 0, m*m*sizeof(complex double));
11 for (int i = 0; i < m; ++i) {
12 target[i*m + i] = d;
13 if(i > 0) target[i*m + i-1] = od;
14 if(i < m - 1) target[i*m + i+1] = od;
16 target[m*(m-1) + m-1] = d/2 + z/(z-1);
18 return 0;
21 int main() {
22 complex double z0 = 150+2*I;
23 double Rx = 148, Ry = 148;
24 int L = 10, N = 50, dim = 400;
25 beyn_contour_t *contour = beyn_contour_ellipse(z0, Rx, Ry, N);
27 beyn_result_t *result =
28 beyn_solve(dim, L, M_function, NULL /*M_inv_Vhat_function*/, NULL /*params*/,
29 contour, 1e-4, 1, 1e-4);
30 printf("Found %zd eigenvalues:\n", result->neig);
31 for (size_t i = 0; i < result->neig; ++i) {
32 complex double eig = result->eigval[i];
33 printf("%zd: %g%+gj\n", i, creal(eig), cimag(eig));
35 free(contour);
36 beyn_result_free(result);
37 return 0;