Additional test to Beyn solver (Example 4.9).

Former-commit-id: 63a78fa09fd3875e5d10b6b4fb6eea72010cfcee
This commit is contained in:
Marek Nečada 2019-09-17 14:11:23 +03:00
parent bd0b8a83e9
commit 42931eb0a0
4 changed files with 68 additions and 2 deletions

View File

@ -19,6 +19,10 @@ add_executable( tbeyn tbeyn.c )
target_link_libraries( tbeyn qpms gsl lapacke amos m )
target_include_directories( tbeyn PRIVATE .. )
add_executable( tbeyn2 tbeyn2.c )
target_link_libraries( tbeyn2 qpms gsl lapacke amos m )
target_include_directories( tbeyn2 PRIVATE .. )
add_executable( tbeyn_gsl tbeyn_gsl.c )
target_link_libraries( tbeyn_gsl qpms gsl lapacke amos m )
target_include_directories( tbeyn_gsl PRIVATE .. )

View File

@ -26,7 +26,7 @@ int main() {
beyn_result_t *result =
beyn_solve(dim, L, M_function, NULL /*M_inv_Vhat_function*/, NULL /*params*/,
contour, 1e-4, 0);
contour, 1e-4, 1e-4);
printf("Found %zd eigenvalues:\n", result->neig);
for (size_t i = 0; i < result->neig; ++i) {
complex double eig = result->eigval[i];

62
tests/tbeyn2.c Normal file
View File

@ -0,0 +1,62 @@
#include <qpms/beyn.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
static double randU(double a, double b) {return a + (b-a) * random() * (1. / RAND_MAX); }
// Normal distribution via Box-Muller transform
static double randN(double sigma, double mu) {
double u1 = randU(0,1);
double u2 = randU(0,1);
return mu + sigma*sqrt(-2*log(u1))*cos(2.*M_PI*u2);
}
struct param49 {
double *T0;
double *T1;
double *T2;
};
// Matrix as in Beyn, example 4.9
int M_function(complex double *target, const size_t m, const complex double z, void *params) {
struct param49 *p = params;
for(size_t i = 0; i < m*m; ++i)
target[i] = p->T0[i] + z*p->T1[i] + z*z*p->T2[i];
return 0;
}
int main(int argc, char **argv) {
complex double z0 = 0;
double Rx = .3, Ry = .3;
int L = 30, N = 150, dim = 60;
if (argc > 1) N = atoi(argv[1]);
beyn_contour_t *contour = beyn_contour_ellipse(z0, Rx, Ry, N);
struct param49 p;
p.T0 = malloc(dim*dim*sizeof(double));
p.T1 = malloc(dim*dim*sizeof(double));
p.T2 = malloc(dim*dim*sizeof(double));
for(size_t i = 0; i < dim*dim; ++i) {
p.T0[i] = randN(1,0);
p.T1[i] = randN(1,0);
p.T2[i] = randN(1,0);
}
beyn_result_t *result =
beyn_solve(dim, L, M_function, NULL /*M_inv_Vhat_function*/, &p /*params*/,
contour, 1e-4, 1e-4);
printf("Found %zd eigenvalues:\n", result->neig);
for (size_t i = 0; i < result->neig; ++i) {
complex double eig = result->eigval[i];
printf("%zd: %g%+gj\n", i, creal(eig), cimag(eig));
}
free(contour);
beyn_result_free(result);
free(p.T0);
free(p.T1);
free(p.T2);
return 0;
}

View File

@ -28,7 +28,7 @@ int main() {
beyn_result_gsl_t *result =
beyn_solve_gsl(dim, L, M_function, NULL /*M_inv_Vhat_function*/, NULL /*params*/,
contour, 1e-4, 0);
contour, 1e-4, 1e-4);
printf("Found %zd eigenvalues:\n", result->neig);
for (size_t i = 0; i < result->neig; ++i) {
gsl_complex eig = gsl_vector_complex_get(result->eigval, i);