Need help with GSL(gnu scientific library).

I have to solve eigenvalue problem for complex hermitian matrix. I decided to use GSL library and everything goes smooth, code is compiling, but I cannot execute output file, when I run it from console I get warning about memory protection violation, and nothing else is happening. I'm wondering if I screwed up something with memory allocation in this one.

Output from console:

xxxxxx@xxxxxx:~$ ./a.out
Naruszenie ochrony pamięci(violation of memory protection)
xxxxx@xxxxxxx:~$



I am using:
g++ (Debian 4.7.2-5) 4.7.2
on Debian 7.5 wheezy
GSL is correctly installed and it was working with other types of eigenvalue problems.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <math.h>
#include <iostream>
#include <stdio.h>
#include <complex>
#include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h>
#include <gsl/gsl_complex_math.h>
#include <gsl/gsl_complex.h>


const  double E0v=-0.8,g1=6.98,g2=2.06,g3=2.93,h=0;

using namespace std;

complex<double> getPk(double kx,double ky,double kz)
{
  complex<double> Pk;
  Pk.real(h*g1*(pow(kx,2)+pow(ky,2)+pow(kz,2))-E0v);
  Pk.imag(0);
  return Pk;
}

complex<double> getQk(double kx,double ky,double kz)
{
  complex<double> Qk;
  Qk.real(h*g2*(pow(kx,2)+pow(ky,2)-2*pow(kz,2)));
  Qk.imag(0);
  return Qk;
}

complex<double> getRk(double kx,double ky,double kz)
{
  complex<double> Rk;
  Rk.real(-sqrt(3)*h*g2*(pow(kx,2)-pow(ky,2)));
  Rk.imag(2*sqrt(3)*h*g3*kx*ky);
  return Rk;
}

complex<double> getSk(double kx,double ky,double kz)
{
  
  complex<double> Sk;
  Sk.real(2*sqrt(3)*h*g3*kx*kz);
  Sk.imag(2*sqrt(3)*h*g3*ky*kz);
  return Sk;
}

int main()
{
	complex<double> i(0.,1.0);
	double kx=0,ky=0;
	double kz=0;
	complex<double>H[4][4];
	H[0][0]=getPk(kx,ky,kz)+getQk(kx,ky,kz);
	H[1][0]=-conj(getSk(kx,ky,kz));

	gsl_eigen_hermv_workspace * w= gsl_eigen_hermv_alloc (4);
    gsl_eigen_hermv_free (w); 
    gsl_matrix_complex *A;
    gsl_vector *eval = gsl_vector_alloc(4);
    gsl_matrix_complex *evec=gsl_matrix_complex_alloc(4,4);
    
    
    for(int i=0;i<4;i++)
    {
		for(int j=0;j<4;j++)
		{
			gsl_complex z;
		    GSL_SET_REAL(&z,real(H[i][j]));
			GSL_SET_IMAG(&z,imag(H[i][j]));
			gsl_matrix_complex_set (A, i,  j, z);
			
		}
	}
	gsl_eigen_hermv (A,eval,evec,w);  
	gsl_eigen_hermv_sort (eval, evec, GSL_EIGEN_SORT_VAL_ASC); 		
    }
You free "w" at line 58 and then use it on line 75.

Line 59 - Don't you need to allocate "A"?
gsl_matrix_complex *A = gsl_matrix_complex_alloc(4, 4);

HTH
Thanks a lot! This solved my problem so far!
Topic archived. No new replies allowed.