7 static double randU(double a
, double b
) {return a
+ (b
-a
) * random() * (1. / RAND_MAX
); }
8 // Normal distribution via Box-Muller transform
9 static double randN(double sigma
, double mu
) {
10 double u1
= randU(0,1);
11 double u2
= randU(0,1);
12 return mu
+ sigma
*sqrt(-2*log(u1
))*cos(2.*M_PI
*u2
);
21 // Matrix as in Beyn, example 4.9
22 int M_function(complex double *target
, const size_t m
, const complex double z
, void *params
) {
23 struct param49
*p
= params
;
25 for(size_t i
= 0; i
< m
*m
; ++i
)
26 target
[i
] = p
->T0
[i
] + z
*p
->T1
[i
] + z
*z
*p
->T2
[i
];
30 int main(int argc
, char **argv
) {
31 complex double z0
= 0;
32 double Rx
= .3, Ry
= .3;
33 int L
= 30, N
= 150, dim
= 60;
34 if (argc
> 1) N
= atoi(argv
[1]);
35 beyn_contour_t
*contour
= beyn_contour_ellipse(z0
, Rx
, Ry
, N
);
37 p
.T0
= malloc(dim
*dim
*sizeof(double));
38 p
.T1
= malloc(dim
*dim
*sizeof(double));
39 p
.T2
= malloc(dim
*dim
*sizeof(double));
40 for(size_t i
= 0; i
< dim
*dim
; ++i
) {
46 beyn_result_t
*result
=
47 beyn_solve(dim
, L
, M_function
, NULL
/*M_inv_Vhat_function*/, &p
/*params*/,
48 contour
, 1e-4, 1, 1e-4);
49 printf("Found %zd eigenvalues:\n", result
->neig
);
50 for (size_t i
= 0; i
< result
->neig
; ++i
) {
51 complex double eig
= result
->eigval
[i
];
52 printf("%zd: %g%+gj\n", i
, creal(eig
), cimag(eig
));
55 beyn_result_free(result
);