title: Generalized diagonalization with Lapack
body: <p>I am having some problems using the subroutine DSYGV of Lapack:</p>
  
  <pre><code>DSYGV( ITYPE, JOBZ, UPLO, N, A, LDA, B, LDB, W, WORK,LWORK, INFO )
  </code></pre>
  
  <p>This is the diagonalization I want to carry out:</p>
  
  <pre><code>v_mat*x = eig*t_mat*x
  </code></pre>
  
  <p>This is the crucial piece of my code:</p>
  
  <pre><code>program pruebadiago
  
  real, dimension(:,:), allocatable :: v_mat, t_mat
  
  real, dimension(:), allocatable   :: eig,WORK
  
  real , parameter                  :: k=3.0,m=4.0
  
  integer, parameter                :: n=2
  
  integer                           :: i
  
  ! EXPECTED EIGENVALUES AND EIGENVECTORS
  
  !eig = 0.286475  ------&gt;  u = (0.262866 , 0.425325)
  
  !eig = 1.96353   ------&gt;  u = (0.425325, -0.262866)
  
  allocate(v_mat(n,n),t_mat(n,n),eig(n))
  
  !--------------------------
  
  v_mat(1,1:2) = (/2.0*k,-k/)
  
  v_mat(2,1:2) = (/-k,k/)
  
  !--------------------------
  
  !--------------------------
  
  t_mat(1,1:2) = (/m,0.0/)
  
  t_mat(2,1:2) = (/0.0,m/)
  
  !---------------------------
  
  !diagonalizacion
  
  call DSYGV( 1, 'v', 'u', n , v_mat, 2 , t_mat, 2, eig, WORK,-1, INF )
  
  LWORK=WORK(1)
  
  allocate(WORK(LWORK))
  
  call  DSYGV( 1, 'v', 'u', n , v_mat, 2 , t_mat, 2, eig, WORK,LWORK, INF )
  
  open(unit=100,file="pruebadiago.dat",status="replace",action="write")
  
  do i = 1,n
  
  write(unit=100,fmt=*) "E",i,"=",eig(i),(v_mat(i,j),j=1,n)
  
  !autofuntzioak zutabeka doaz"(100f12.6)"
  
  enddo
  
  close(unit=100)
  
  deallocate(v_mat,t_mat,eig,WORK)
  
  end program pruebadiago
  </code></pre>
  
  <p>I think I understood everything given in this document:</p>
  
  <pre><code>http://www.netlib.org/lapack/lapack-3.1.1/html/dsygv.f.html
  </code></pre>
  
  <p>But the argument LWORK which I did not understand so I just try different values.</p>
  
  <p>I know something is wrong because I know what are the eigenvalues and eigenvectors of this matrix and I get wrong eigenvalues and eigenvectors, and I am doing such a simple calculation in order to understand the way it works and then compute huge diagonalizations.</p>
  
  <p>Does anybody see what is the problem?</p>
  
  <p>Thank you</p>